Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't the Part reduce my health to 0 when I touch it?

Asked by 5 years ago

Part = script.Parent Part.Touched:Connect(function(hit) if hit.Parent == hit.Parent:FindFirstChild("Humanoid") then hit.Parent.Health = 0 end Part.CFrame = CFrame.new(0, 0, 15) end)

2 answers

Log in to vote
0
Answered by 5 years ago
local Part = script.Parent
Part.Touched:Connect(function(hit)
    local human = hit.Parent:FindFirstChildOfClass("Humanoid") 
    if human then
        human.Health = 0
        Part.CFrame = CFrame.new(0, 0, 15)
    end
end)
0
Thanks FireCoolflame 21 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

try this... local Part = script.Parent

local function onPartTouch(otherPart) local partParent = otherPart.Parent local humanoid = partParent:FindFirstChildWhichIsA("Humanoid") if humanoid then humanoid.Health = 0 end end Part.Touched:Connect(onPartTouch)

Answer this question