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

Touch function repeating, even if not touching?[Unanswered]

Asked by 9 years ago

I made this script, it makes an fire instance on the part that touched it, and it kinda works! It does that and all, unfortunately it keeps making fire instances until the player is dead!!! How can I fix this? I know the problem is the "While - do" but I use that to make sure that it is a player (not just a random brick)! Here is my script

function onTouched(hit)
    while hit.Parent.Humanoid do
        wait(0.000001)

            if script.CanSpreadFire.Value == 1 then             
                wait(0.000001)
                script.CanSpreadFire.Value = 0              
                local fire = Instance.new("Fire")
                fire.Parent = hit
                fire.Color = Color3.new(77,175,236)
                fire.Heat = 9
                fire.Size = 2               
                local burn = script.Burn:clone()
                burn.Parent = fire
                hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5
                wait(1)
                script.CanSpreadFire.Value = 1
            end


    end

end

script.Parent.Touched:connect(onTouched)

Please help!!! Thank you!!!

1 answer

Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

You're using a while loop after the part is touched, which means whatever is inside it will run repeatedly. You mean to use a conditional if then statement; if hit.Parent:FindFirstChild("Humanoid")then

Ad

Answer this question