#alternatives to wait()
104 messages · Page 1 of 1 (latest)
local function SpawnBuildings()
local CurrentBuildingsFolder = game.ReplicatedStorage:WaitForChild("Scenery"):FindFirstChild(playerUI.Scenery.Scene.Value).Background.Buildings
--\\for i = 1, 1 do
local BuildingOdds = math.random(1, 2)
if CurrentBuildingsFolder:FindFirstChild("Building" .. BuildingOdds) then
print("Spawning buildings")
local CurrentBuilding = CurrentBuildingsFolder:FindFirstChild("Building" .. BuildingOdds):Clone()
CurrentBuilding.Name = "Building"--i
CurrentBuilding.Parent = SceneryFolder:WaitForChild("BuildingsFolder")
--
for i,BuildingPart in pairs(CurrentBuilding:GetChildren()) do
if BuildingPart:IsA("BasePart") or BuildingPart:IsA("MeshPart") then
local BuildingInfo = TweenInfo.new(12, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local BuildingGoals = {Position = Vector3.new(BuildingPart.Position.Z * 5,49.4,-169.746)}
BuildingTween = TweenService:Create(BuildingPart,BuildingInfo,BuildingGoals)
BuildingTween:Play()
delay(1,function()
if playerUI.GameInSession.Value == true then
SpawnBuildings()
else
end
end)
end
end
Use coroutine
wait() is to... wait... Is that obvious? What do you expect to do...?
im saying
when i put wait
for the delay(1,function()
it pauses the script
this is a funciton
meaning a wait will pause the function the function is being called in
local function SpawnScenery()
EndScenery()
-------------------------- Background
local Floor
local Tunnel = game.ReplicatedStorage:WaitForChild("Scenery"):FindFirstChild(playerUI.Scenery.Scene.Value).Main.Tunnel:Clone() --- FIX!!!
Tunnel.Parent = SceneryFolder
local tunnelY = math.random(37,60)
Tunnel.PrimaryPart.CFrame = CFrame.new(Tunnel.PrimaryPart.CFrame.X, tunnelY, Tunnel.PrimaryPart.CFrame.Z)
EventsFolder.NewTunnel:FireServer(tunnelY)
if SceneryFolder:FindFirstChild(playerUI.Scenery.Scene.Value .. "Floor") then
else
local CurrentSceneryFolder = ReplicatedStorage.Scenery:WaitForChild(playerUI.Scenery.Scene.Value)
local SceneName = playerUI.Scenery.Scene.Value
Floor = CurrentSceneryFolder.Main:FindFirstChild(SceneName .. "Floor"):Clone()
Floor.Parent = SceneryFolder
Floor.Position = Vector3.new(Tunnel.PointPart.Position.X,0,Tunnel.PointPart.Position.Z * -16)
end
--SpawnTrees()
SpawnBuildings()
Tweens(Tunnel, Floor)
if playerUI.GameInSession.Value == false then
print("game not in sesstion")
BuildingTween:Pause()
else
SpawnScenery()
print(playerUI.GameInSession.Value)
print("Spawn Scenery Function Called")
end
end
this is whats calling it
@steady olive
@cobalt pollen '
""""" """""""""""""""""""""""""""""""""""""""'
'''"'"'''""""""""""""""""""''''"""""""""'''''''""""""''''"""'''"""''""'"'"'''""'""""'"''''"'""""""""
Hmm yes
u see
Delay doesn't stop the script
wait does
and delay isnt being accurate
the buidlings arent spawning at a constant pause time
like
they start
correct
then they end up inside each other
try task.wait() then
I don't think the problem is the task.delay ?
nope
just realized
ima send a video
see the buildings spawn inside each other sometimes
and others they stack
ima send it with pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
add it there?
i just realized i had a tween
then i put wait
in the tweens() function
i hav e a tween
so that wait made it onger
still doign it
its liek it spawns 2 at one
it spawns 1 at once
then 2 at once
debounce\
?
omg
yo
the sceneryspawn function
is calling for the buildings
and also
the buildings function is calling fro the buildings
maybe thats the issue
local function SpawnScenery()
coroutine.wrap(function()
while task.wait(1) do
EndScenery()
-------------------------- Background
local Floor
local Tunnel = game.ReplicatedStorage:WaitForChild("Scenery"):FindFirstChild(playerUI.Scenery.Scene.Value).Main.Tunnel:Clone() --- FIX!!!
Tunnel.Parent = SceneryFolder
local tunnelY = math.random(37,60)
Tunnel.PrimaryPart.CFrame = CFrame.new(Tunnel.PrimaryPart.CFrame.X, tunnelY, Tunnel.PrimaryPart.CFrame.Z)
EventsFolder.NewTunnel:FireServer(tunnelY)
if SceneryFolder:FindFirstChild(playerUI.Scenery.Scene.Value .. "Floor") then
else
local CurrentSceneryFolder = ReplicatedStorage.Scenery:WaitForChild(playerUI.Scenery.Scene.Value)
local SceneName = playerUI.Scenery.Scene.Value
Floor = CurrentSceneryFolder.Main:FindFirstChild(SceneName .. "Floor"):Clone()
Floor.Parent = SceneryFolder
Floor.Position = Vector3.new(Tunnel.PointPart.Position.X,0,Tunnel.PointPart.Position.Z * -16)
end
--SpawnTrees()
SpawnBuildings()
Tweens(Tunnel, Floor)
if playerUI.GameInSession.Value == false then
print("game not in sesstion")
BuildingTween:Pause()
break
else
print(playerUI.GameInSession.Value)
print("Spawn Scenery Function Called")
end
end
end)()
end
what about? ```lua
task.delay(5,function()
-- runns after 5 seckonds without stopping the script
end)
where
its not running all the tim
local function SpawnScenery()
EndScenery()
-------------------------- Background
local Floor
local Tunnel = game.ReplicatedStorage:WaitForChild("Scenery"):FindFirstChild(playerUI.Scenery.Scene.Value).Main.Tunnel:Clone() --- FIX!!!
Tunnel.Parent = SceneryFolder
local tunnelY = math.random(37,60)
Tunnel.PrimaryPart.CFrame = CFrame.new(Tunnel.PrimaryPart.CFrame.X, tunnelY, Tunnel.PrimaryPart.CFrame.Z)
EventsFolder.NewTunnel:FireServer(tunnelY)
if SceneryFolder:FindFirstChild(playerUI.Scenery.Scene.Value .. "Floor") then
else
local CurrentSceneryFolder = ReplicatedStorage.Scenery:WaitForChild(playerUI.Scenery.Scene.Value)
local SceneName = playerUI.Scenery.Scene.Value
Floor = CurrentSceneryFolder.Main:FindFirstChild(SceneName .. "Floor"):Clone()
Floor.Parent = SceneryFolder
Floor.Position = Vector3.new(Tunnel.PointPart.Position.X,0,Tunnel.PointPart.Position.Z * -16)
end
--SpawnTrees()
SpawnBuildings()
Tweens(Tunnel, Floor)
task.wait(1)
if playerUI.GameInSession.Value == false then
print("game not in sesstion")
BuildingTween:Pause()
else
SpawnScenery()
print(playerUI.GameInSession.Value)
print("Spawn Scenery Function Called")
end
end
tryin
the tunnel and the buildings go at a different pace
so if i make the task wait longer
task.wait(1)
if playerUI.GameInSession.Value == false then
print("game not in sesstion")
BuildingTween:Pause()
else
SpawnScenery()
print(playerUI.GameInSession.Value)
print("Spawn Scenery Function Called")
end
end
i fi make it longer
the tunel spawns at a regular pace
but teh buildings have a big gap
@cobalt pollen
💀
i would say use delay
and have a function in it
i dont know much about task.delay
but uh
it seems good to me
idk im gonna just stop there
** You are now Level 14! **
shut up
task.delay delays the function by the timeout