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

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

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)

2 comments

0

It happens when the fire is destroyed in the second event listener but you parent it in the first event listener.

0

So how would I fix it? Can you resolve my script for me?

1 answer

✓ Accepted answer

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

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