#alternatives to wait()

104 messages · Page 1 of 1 (latest)

tulip wigeon
#

its pausing my whole script bro

steady olive
tulip wigeon
#
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
cobalt pollen
#

Use coroutine

tulip wigeon
#

i was just resezrching it

#

but. saw too many words and left

steady olive
#

wait() is to... wait... Is that obvious? What do you expect to do...?

tulip wigeon
#

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 '

#

""""" """""""""""""""""""""""""""""""""""""""'

#

'''"'"'''""""""""""""""""""''''"""""""""'''''''""""""''''"""'''"""''""'"'"'''""'""""'"''''"'""""""""

steady olive
#

Hmm yes

tulip wigeon
#

u see

cobalt pollen
#

Delay doesn't stop the script

tulip wigeon
#

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

steady olive
#

try task.wait() then

tulip wigeon
#

ok

#

actually

#

i think that that isnt the issue

cobalt pollen
tulip wigeon
#

nope

#

just realized

#

ima send a video

#

see the buildings spawn inside each other sometimes

#

and others they stack

#

ima send it with pastebin

cobalt pollen
#

task.wait(1)?

#

Or while task.wait(1) loop?

tulip wigeon
#

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

cobalt pollen
#

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
cinder egret
#

what about? ```lua
task.delay(5,function()
-- runns after 5 seckonds without stopping the script
end)

tulip wigeon
#

where

tulip wigeon
cobalt pollen
#
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
tulip wigeon
#

tryin

tulip wigeon
#

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

tulip wigeon
#

@cobalt pollen

long copper
#

or

#

use task.wait

#

wait i just realized

#

im dumb

#

i need to read

tulip wigeon
#

💀

long copper
#

i would say use delay

tulip wigeon
#

yea

#

we are

long copper
#

and have a function in it

tulip wigeon
#

💀💀💀

#

uhh

#

u kinda gotta read everything

#

also specify where

long copper
#

i dont know much about task.delay

#

but uh

#

it seems good to me

#

idk im gonna just stop there

agile ruinBOT
#

studio** You are now Level 14! **studio

long copper
#

shut up

tulip wigeon
#

bluds mad at the boy

#

bot

#

it’s fine bro

indigo breach
tulip wigeon
#

yeah

#

we konw

#

you kinda gotta read from the beginning