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

How do you put a player on fire when they touch something?

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!

1 answer

✓ Accepted answer

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.

3 comments

0

Thank you so much! I will try this right away. :)

0

It worked! Thank you, now I can make a realistic lava brick.

0

glad to help

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