I want a fire spread system, but mine isn’t exactly going as planned.
What’s wrong is that:
- It spreads once then stops
- Parts of Parts don’t spread fire
My code:
local function CastRecieved(Part)
if Part ~= nil then
warn("New Part caught on fire")
local Fire = Instance.new("Fire", Part)
Fire.Size = Part.Size.Z*1.25
game.ReplicatedStorage:WaitForChild("NewFire"):Fire(Part)
print('New Fire for Part')
end
end
local CastRange = 3
local DisintegrateTime = 15
game.ReplicatedStorage:WaitForChild("NewFire").Event:Connect(function(part)
spawn(function()
part.Material = Enum.Material.Slate
game:GetService("TweenService"):Create(part, TweenInfo.new(DisintegrateTime), {Color = Color3.fromRGB(20, 9, 0)}):Play()
wait(DisintegrateTime)
part:Destroy()
end)
spawn(function()
for i = 1, 10 do
wait(1)
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {part}
local CastType = math.random(1, 6)
if CastType == 1 then
local Cast = workspace:Raycast(part.Position, -Vector3.zAxis*CastRange, Params)
if Cast then
CastRecieved(Cast.Instance)
break
end
elseif CastType == 2 then
local Cast = workspace:Raycast(part.Position, Vector3.zAxis*CastRange, Params)
if Cast then
CastRecieved(Cast.Instance)
break
end
elseif CastType == 3 then
local Cast = workspace:Raycast(part.Position, -Vector3.xAxis*CastRange, Params)
if Cast then
CastRecieved(Cast.Instance)
break
end
elseif CastType == 4 then
local Cast = workspace:Raycast(part.Position, Vector3.xAxis*CastRange, Params)
if Cast then
CastRecieved(Cast.Instance)
break
end
elseif CastType == 5 then
local Cast = workspace:Raycast(part.Position, -Vector3.yAxis*CastRange, Params)
if Cast then
CastRecieved(Cast.Instance)
break
end
elseif CastType == 6 then
local Cast = workspace:Raycast(part.Position, Vector3.yAxis*CastRange, Params)
if Cast then
CastRecieved(Cast.Instance)
break
end
end
end
end)
end)
Did not spread after about 5 seconds:
If you have any idea of what could be wrong, please help me! Thanks!