I know how to do an onTouched function:
function onTouched(part) end script.Parent.Touched:connect(onTouched)
But I'd like to know how to put the user who touched it on fire. I have a damage brick but I'd like a more realistic effect.
Damage = script.Parent.Damage.Value function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = h.Health - Damage end end script.Parent.Touched:connect(onTouched)
^ That is my script so far! I've tried many things like:
Damage = script.Parent.Damage.Value function onTouched(part) local fire = Instance.new("Fire") fire.Parent = game.Players.LocalPlayer.Torso fire.heat = 5 fire.size = 30 local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = h.Health - Damage end end script.Parent.Touched:connect(onTouched)
^ This script just breaks the entire brick! Thank you to everyone one who - tries to - help me!
Well you are using LocalPlayer, which can only be used in a LocalScript. The parameter you used in the function Touch (which is 'part') is whatever hit that brick. Instead of game.Players.LocalPlayer, use part.Parent:FindFirstChild("Humanoid"). This will try and find if the part's parent has a humanoid child. You can apply this to your code as such:
Damage = script.Parent.Damage.Value function onTouched(part) local fire = Instance.new("Fire") fire.Parent = part.Parent:FindFirstChild("Humanoid").Torso fire.heat = 5 fire.size = 30 local h = part.Parent:FindFirstChild("Humanoid") if h~=nil then h.Health = h.Health - Damage end end script.Parent.Touched:connect(onTouched)
You should also add a debounce to keep the player from insta-dying.