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

Make a part that when you touch it it will make you take damage?

Asked by 3 years ago

I need help making a part that will make you take damage if you touch it. Thanks!

function onTouch(hit)
    if game.Players:FindFirstChild(hit.Parent.Name) ~= nil then
        Character.Humanoid:TakeDamage(10)
        script.Parent:Destroy()
    end
end

script.Parent.Touched:Connect(onTouch)

1 answer

Log in to vote
1
Answered by 3 years ago

This script doesn't work because "Character" is not defined anywhere. It will work if you define Character as hit.Parent, or if you replace line 4 with hit.Parent.Humanoid:TakeDamage(10)

0
Thank you! User#39520 0 — 3y
Ad

Answer this question