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

This 'kill on touch'script does not kill when touching? [solved]

Asked by 6 years ago
Edited by Shawnyg 6 years ago

How could I upload a mesh to roblox,so people can take my mesh model. Any help would be appreciated!

And also,the question.

function onTouch(part) 
    local humanoid = part.Parent:FindFirstChild("Humanoid") 
    if (humanoid = nil) then    
    humanoid.Health = 0 
end
end

script.Parent.Touched:connect(onTouch)

Any help for both questions? Thanks.

0
It's because in the second line you're telling it if Humanoid is nil then to set the humanoid health to 0. You'll want to identify if the humanoid isn't nil. So in this case you'd do 'if humanoid ~= nil' then on line 3. M39a9am3R 3210 — 6y
0
Thanks,it worked! ThisIsTheBestName18 0 — 6y
0
Edited the title to say [solved] Shawnyg 4330 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

All you need is this:

local debounce = false
script.Parent.Touched:Connect(function(hit)
    if debounce == false and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid.Health > 0 then
        debounce = true
        hit.Parent.Humanoid.Health = 0 -- This might kill the player even if they have a force field...
        debounce = false
    end
end)

Hope this helped!

Ad

Answer this question