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

how do I make someones humanoid take damage when they touch a part named "SmokeE"?

function onTouch(Part)
Part.Parent:TakeDamage(4)
end
script.Parent.Touched:connect(onDamage)

2 answers

Need more information. This is a simple script which searches for a Humanoid and then gives damage(with debounce).

local touched = false
script.Parent.Touched:connect(function(part)
	if not touched then
		touched = true
		local humanoid = part.Parent:findFirstChild('Humanoid')
		if humanoid then
		humanoid:TakeDamage(4)
		end
	touched = false
	end
end)

You messed up a bit by having the function named "onTouch" and having the .Touched:connect(onDamage). To fix this all you have to do is this:

function onTouch(Part)
Part.Parent:TakeDamage(4)
end
script.Parent.Touched:connect(onTouch)

That should fix your script.

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