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

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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.

0
Thank you so much! I will try this right away. :) AidanTES 36 — 5y
0
It worked! Thank you, now I can make a realistic lava brick. AidanTES 36 — 5y
0
glad to help TheLionLiar 39 — 5y
Ad

Answer this question