Cloned scripts don't work

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I’m trying to make a fire that spreads and burns and eventually destroys a part in 20 seconds.

  1. What is the issue? Include screenshots / videos if possible!

In around a minute when everything is going fine, the fires don’t seem to be doing their job, they stop spreading and instead of destroying the parts they stay in them forever. There’s also a message in the output that reads:

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

Which I’m pretty sure is the problem.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve seen a lot of people have the same output message as me but I can’t find a solution for my specific situation.

local thisFire = script.Parent
local startedTime = tick()
burningPart = script.Parent.Parent
local spreadedFire = thisFire:Clone()
				spreadedFire.Heat = spreadedFire.Heat/2
				spreadedFire.Size = spreadedFire.Size/2




function Spread(part)
	local check = part:findFirstChild("Fire")
	if check == nil then 
		if not (part.Name == "Baseplate" or part.Parent.ClassName == "Tool") then 
		wait(3)
		spreadedFire.Parent = part
			end
	end
end

while true do
wait(0.00001)
local fireTime = tick() - startedTime
script.Parent.Parent.Touched:connect(Spread)

if fireTime >= 10 then
	burningPart.BrickColor = BrickColor.new("Black")
end
if fireTime >= 20 then
	burningPart:Destroy()
end
	end

I also have another script inside the fire that makes the fire grow if that’s useful for anyone.

local fire = script.Parent


while fire.Heat <= 25 or fire.Size <= 30 do
		wait(3)
		fire.Heat = fire.Heat + 2
		fire.Size = fire.Size + 2
end
1 Like

You never set the parent of the clone!
You can do this by doing spreadedFire.Parent = partyouwanttospreadfire

1 Like

I set the parent of the clone in the Spread function.

1 Like

Well, when the clone function runs, the parent never gets set, so it just defaults to null, you have to set it when the clone function is ran. Best thing to do is to clone it in the Spread function.

1 Like

Well that did make it better now, more fires are working than before, but there are still some fires that will stay and do nothing. Also my game is more laggier

Try increasing the wait time from 0.00001 to 1 or 0.1 maybe to reduce the lag?

I don’t know how many parts are touching at one time, but you don’t have any type of checks to see if a part is already burning, so it is probably trying to spread to the same parts over and over again.

Perhaps test it in studio and hit the pause button once the burning seems to stop spreading and you will find that you are making a ton of fires for the same part and that is causing the lag.

edit: nevermind I see it now

I put the wait time there because while loops have a tendency to time out.

I have a check inside the spread function, and I’m using 72 parts, but I don’t think it’s the parts that are causing it because it didn’t lag on previous tries.

The wait() is needed, but the amount of time is too small.
You are basically running the loop 10,000 times a second which is way too much.
You probably only need a second delay or maybe 0.1, but 0.00001 is too small.
If you added just wait() IIRC it would run every 0.03 seconds and you are running that while loop much faster than that.

1 Like

Ok so I found out what was causing the lag, if I put the fire clone variable inside the spread function it will burn many parts at the same time instead of waiting 3 seconds. I started modifying many things in my script and it’s getting better now. Fires that don’t run their scripts still exist though, and sometimes they don’t even have the scripts inside them at all. Usually their heat is set to 0.

Current script:

local thisFire = script.Parent
local startedTime = tick()
local burningPart = thisFire.Parent
local spreadedFire = thisFire:Clone()

					





function Spread(part)
	
	local check = part:findFirstChild("Fire")
	if check == nil then
		wait(3)
		if not (part.Name == "Baseplate")  then 
			if part ~= nil then
				spreadedFire.Heat = spreadedFire.Heat/2
				spreadedFire.Size = spreadedFire.Size/2
				if (spreadedFire.Heat <= 0 or spreadedFire.Size <= 0) then
					spreadedFire.Heat = 3
					spreadedFire.Heat = 1
				end
				spreadedFire.Parent = part
				end
			end
	end
end

while true do
wait(0.1)
local fireTime = tick() - startedTime
burningPart.Touched:connect(Spread)

if fireTime >= 10 then
	burningPart.BrickColor = BrickColor.new("Black")
end
if fireTime >= 20 then
	thisFire.Enabled = false
		wait(0.00001)
	thisFire:Remove()
		wait(0.00001)
	burningPart:Remove()
end
	end