Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

3 comments

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.

0

Thanks,it worked!

0

Edited the title to say [solved]

1 answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.