I need help scripting a spreading fire system as a fun little project. However, i keep running into problems.
The fire dosen’t spread. Here is the code:
math.randomseed(os.time())
local spreadtime = 3
local distance = 2
while wait(spreadtime) do
for i,v in pairs(workspace.Flammables:GetChildren()) do
local onfire = false
for r,e in pairs(workspace.Flammables:GetChildren()) do
if e ~= v then
local amount = math.random(1,3)
local x = v.Position.X+distance
local y = v.Position.Y+distance
local z = v.Position.Z+distance
local x2 = v.Position.X-distance
local y2 = v.Position.Y-distance
local z2 = v.Position.Z-distance
local min = v.Position - (distance * v.Size)
local max = v.Position + (distance * v.Size)
local fires = 0
local area = Region3.new(min,max)
print(area.Size)
local parts = workspace:FindPartsInRegion3(area,nil,3)
if not e:FindFirstChild("Fire") then
if parts[e] then
local msg = "Fire spread from "..v.Name.." to "..e.Name
print(msg)
local clone = game.ServerStorage.Fire:Clone()
clone.Parent = e
fires = fires + 1
wait(spreadtime-1)
fires = 0
end
end
end
end
end
end
Any help is appreciated.