英文:
I dont understand what is wrong with my humanoid code?
问题
以下是代码的翻译部分:
local sinkpart = script.Parent
local function sink(otherpart)
print("kill part touched")
local people = otherpart.Parent
local humanoid = people:FindFirstChild("humanoid")
if humanoid then
humanoid.Health = 0
end
end
sinkpart.Touched:Connect(sink)
请注意,我只提供了代码的翻译部分,不包括问题或其他内容。
英文:
local sinkpart = script.Parent
local function sink(otherpart)
print("kill part touched")
local people = otherpart.Parent
local humanoid = people:FindFirstChild("humanoid")
if humanoid then
humanoid.Health = 0
end
end
sinkpart.Touched:Connect(sink)
when i touced the part, the part doesnt kill the character can anyone explain the problem
I want it to kill who ever touches it
答案1
得分: 1
问题似乎是因为尝试将"humanoid"作为"people"的子项来查找,假设otherPart.parent将是玩家的角色。在Roblox中,按名称访问子项是区分大小写的,所以尝试使用"Humanoid",像这样:
local sinkpart = script.Parent
local function sink(otherpart)
print("kill part touched")
local people = otherpart.Parent
local humanoid = people:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
sinkpart.Touched:Connect(sink)
英文:
The issue seems to be due to trying to find "humanoid" as a child of people
, assuming otherPart.parent will be a player's character. Accessing children by name in Roblox is case-sensitive, so try using "Humanoid" instead, like this:
local sinkpart = script.Parent
local function sink(otherpart)
print("kill part touched")
local people = otherpart.Parent
local humanoid = people:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
sinkpart.Touched:Connect(sink)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论