我不理解我的人形代码有什么问题?

huangapple go评论59阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年5月15日 08:29:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76250221.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定