Hey there! I am trying to create spill system that workers can clean up. The problem is that the spill spawns sideways and then it doesn’t spawn after the wait time.
This is the current code I have:
local Wait_Time = 10
local Spill = script.SpillSample
local SpillZones = game.Workspace.SpillLocations:GetChildren()
local RandomLocation = SpillZones[math.random(1, #SpillZones)]
while task.wait(Wait_Time) do
local newSpill = Spill:Clone()
newSpill.BrickColor = BrickColor.random()
newSpill.Parent = RandomLocation
newSpill.CFrame = RandomLocation.CFrame
print("Spawned Spill")
end
maybe the union orientation is not correct, you can use the surface orientation indicator to see the front face and compare it with the brick where the spill is supposed to spawn
local Wait_Time = 10
local Spill = script.SpillSample
local SpillZones = game.Workspace.SpillLocations:GetChildren()
--[[
local RandomLocation = SpillZones[math.random(1, #SpillZones)] before random location would always be the same
because it was outside of the loop
]]
while task.wait(Wait_Time) do
local RandomLocation = SpillZones[math.random(1, #SpillZones)] -- moved here
local newSpill = Spill:Clone()
newSpill.BrickColor = BrickColor.Random()
newSpill.Parent = RandomLocation.Parent
newSpill.CFrame = RandomLocation.CFrame * CFrame.Angles(0,0,math.rad(90))
print("Spawned Spill")
end