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

My onTouch Fire Script shows a roblox error in the code. How do I fix it?

Asked by 5 years ago

So basically my script works once or twice but then shows a Roblox error and I don't know how to fix it. Down here is what it says when I touch the 2 parts. (1 part burns me and the other extinguishes the fire)

The Parent property of Fire is locked, current parent: NULL, new parent Handle

PART 1

f = Instance.new("Fire")

script.Parent.Touched:Connect(function(Touch)
    if not Touch:FindFirstChild("Humanoid") then
        f.Parent = Touch
        print(Touch.Name)
    end
end)

PART 2

script.Parent.Touched:Connect(function(water)
    if water:FindFirstChild("Fire") then
    water.Fire:Destroy()
    end
end)
0
It happens when the fire is destroyed in the second event listener but you parent it in the first event listener. Rheines 661 — 5y
0
So how would I fix it? Can you resolve my script for me? FearlessX96 74 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Firstly, you can place both functions into the same connection (you'd only need one script), since you want these to occur chronologically, you'd place the water code after the adding fire code.

script.Parent.Touched:Connect(function(Touch)
    local f = Instance.new("Fire")
    if not Touch:FindFirstChild("Humanoid") then
        f.Parent = Touch
        print(Touch.Name)
    end

    if Touch:FindFirstChild("Fire") then
        Touch.Fire:Destroy()
    end
end)

For the second script, if you keep two separate ones, you can also change the .Touched to a .ChildAdded event, where the parameter is the added instance

Revision Script 2

script.Parent.ChildAdded:Connect(function(fire)
    if fire.Name == "Fire" then
        fire:Destroy()
    end
end)

You should also place the "fire" into the event connection since creating the fire outside of the connection will result in only ever having one "Fire" instance

Ad

Answer this question