This code here is supposed to spread fire, similar to the fire in Natural Disaster Survival. It works when it is fired on by a remote event. It works great the first time you use it. The issue I’m facing starts when you fire the event a second time. For some reason it wont spread the fire. I know everything is working up to this point:
if table.find(found_parts, v) and v:GetAttribute("burned") == nil and v:GetAttribute("wontBurn") == nil and state == 0 then
For some reason the second time the fire spreads it’s not meeting one of these requirements in the if statement
. I don’t know which one, though. It should meet all of them. You can see in the image attached it does:
Main Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ZoneModule = require(ReplicatedStorage.Zone)
local spreadSpeed = 0.05
--//Select Starting Random Position//
local function choose_start_position()
print("CHOOSING STARTING POS")
local container = ZoneModule.new(game.Workspace:FindFirstChild("ZoneContainer"))
parts = container:getParts()
local chosenStartingPoint = parts[math.random(1,#parts)]
return chosenStartingPoint
end
local state = 0
--//Main Loop//
local original_info ={}
local function remote_event(start_part, speed)
if state == 0 then
burned_parts = {start_part}
print(state)
for _, burned_part in burned_parts do
found_parts = workspace:GetPartBoundsInRadius(burned_part.Position,(burned_part.Size.X + burned_part.Size.Y + burned_part.Size.Z) * 0.5) -- Get all parts that the burned part hitbox is touching
print(found_parts)
for _, v in found_parts do -- Check if the new part is touching the burned part
if table.find(found_parts, v) and v:GetAttribute("burned") == nil and v:GetAttribute("wontBurn") == nil and state == 0 then
--//Visual Effects//
local OriginalColor = v.Color
local OriginalMaterial = v.Material
table.insert(burned_parts, v)
original_info[v] = {OriginalColor, OriginalMaterial}
v.Color = Color3.fromRGB(255, math.random(50,144), 0)
v.Material = Enum.Material.Neon
script.FireParticle:Clone().Parent = v
v:SetAttribute("burned", true)
task.wait(speed)
end
end
end
end
end
--//Return Burnt Parts To Their Original Look//
local function return_state(Container, SFX)
for part, originalData in original_info do
part.Color = originalData[1]
part.Material = originalData[2]
part:FindFirstChild("FireParticle"):Destroy()
end
for _,v in burned_parts do
v:SetAttribute("burned", false)
end
table.clear(burned_parts)
table.clear(original_info)
table.clear(found_parts)
table.clear(parts)
Container:Destroy()
SFX.Playing = false
print(burned_parts)
end
--//Connect To Bindable Events//
ReplicatedStorage:WaitForChild("DisastersEvents").Fire.OnServerEvent:Connect(function(Player, Stage)
if Stage == 0 then
state = 0
print("passed")
Container = script:FindFirstChild("ZoneContainer"):Clone()
SFX = script.SoundSFX
Container.Parent = game.Workspace
SFX.Playing = true
remote_event(choose_start_position(), spreadSpeed)
else
state = 1
return_state(Container, SFX)
end
end)
Video: