This is a small project I’m working on making a fire system similar to the one in Natural Disaster Survival. Everything works great but the fire won’t spread. I’ve tried to use ChatGPT for hours trying to fix it and it doesn’t work. I’ve tried different ways to make the fire spread:
- When a part touches a fire part
- When a part is 3 studs or closer to a fire part (using rn)
It doesn’t give me any warnings or errors. Please help.
This is my script:
local function deleteWelds(part, model)
for _, modelPart in pairs(model:GetDescendants()) do
for _, weld in pairs(modelPart:GetChildren()) do
if weld:IsA("WeldConstraint") then
if weld.Part1 == part or weld.Part0 == part then
weld:Destroy()
end
end
end
end
end
local function setPartOnFire(part, model)
if part:FindFirstChild("Burning") then return end
part.Name = "FirePart"
local burning = Instance.new("BoolValue")
burning.Name = "Burning"
burning.Parent = part
local fire = Instance.new("Fire")
fire.Size = 25
fire.Parent = part
part.Material = Enum.Material.Neon
part.Color = Color3.fromRGB(255, 200, 25)
local colors = {
Color3.fromRGB(255, 200, 25),
Color3.fromRGB(240, 121, 1),
Color3.fromRGB(240, 69, 21),
Color3.fromRGB(41, 42, 42)
}
local burnTime = 20
local stageTime = burnTime / 4
for i = 2, 4 do
wait(stageTime)
part.Color = colors[i]
if i == 3 then
part.Anchored = false
deleteWelds(part, model)
end
if i == 4 then
fire:Destroy()
end
end
part.Color = colors[4]
burning:Destroy()
end
local function spreadFire(part, model)
for _, otherPart in pairs(model:GetChildren()) do
if not otherPart:FindFirstChild("Burning") and (otherPart.Position - part.Position).Magnitude <= 3 then
wait(1)
setPartOnFire(otherPart, model)
end
end
end
local tower = game.Workspace:WaitForChild("Tower")
local function startFire(model)
local partsInModel = model:GetChildren()
local randomPart = partsInModel[math.random(1, #partsInModel)]
setPartOnFire(randomPart, model)
end
startFire(tower)
while true do
wait(1)
for _, part in pairs(tower:GetChildren()) do
if part:FindFirstChild("Burning") then
spreadFire(part, tower)
end
end
end
Edit: It seems like theres a problem with the StartFire() function, I tried running it multiple times and it kept picking the exact same part in the model of hundreds of other parts.
I also tried doing it multiples times like this:
local repeatTimes = 50
for i = 1, repeatTimes do
startFire(tower)
end
It only did it once.