#How can i run a code after all players are loaded ?

1 messages · Page 1 of 1 (latest)

fathom burrow
#

Players are being teleported from lobby to a different place (same game), but
some players load faster than others and the game breaks.

lilac salmon
#

Use game.Players:GetPlayers and save that to a variable

#

then use a remote event in replicated storage

#

on a localscript

#

listen for the game.Loaded event

#

then fire the event

#

when all players have fired

fathom burrow
#

ok should i put it on startercharacter ?

lilac salmon
#

starterplayer

fathom burrow
#

okey

lilac salmon
#

also use task.wait

#

:)

fathom burrow
#

thanks ill try it

lilac salmon
#

task.wait(10)

#

it works just like wait

fathom burrow
#

so there wont be a problem beacuse some times the players that join will be 4 and sometimes 2

lilac salmon
#

yes

#

as long as you keep track of what players loaded

fathom burrow
#

ok

#

this what i made so far

lilac salmon
#

game.Loaded:Wait()
LoadedEvent:Fire()

strong geyser
#
game.Players.PlayerAdded:Connect(function(player)
    print("There are", #game.Players:GetPlayers(), "players in the game")
end)
fathom burrow
#

where should i put it ?

strong geyser
#

where ever you want

#

it will work in a normal script and a localscript

fathom burrow
#

okey thanks

strong geyser
#

it can go in workspace, replicatedfirst, serverscriptservice, starterplayerscripts, startergui

fathom burrow
#

ok

#

can i synchronize it with a countdown timer ?

strong geyser
#
game.Players.PlayerAdded:Connect(function(player)
    -- if there are less then 5 players then return and do nothing
    if #game.Players:GetPlayers() < 5 then return end
    -- start timer now that we have 5 players
end)
fathom burrow
#

nice

quartz apex
#

If you want the most accurate

#

u need script on client to detect whether it's loaded or not

#

Once loaded let the server know while waiting for other

#

Once all players loaded, call the function

#

Content provider service very useful

#

You might also need to implement timeout so other players won't have to wait so long

#

If you only use game.Loaded:Wait() then it's not accurate at all, this only fire after client got the game object. They don't check whether content fully loaded or not.

quartz apex
fathom burrow
#

ok

fathom burrow
#

i made a script in serverscript service to know when a player has joined the server

fathom burrow
fathom burrow
fathom burrow
#

okey a function ?

#

or remote event ?

quartz apex
#

Remote event

fathom burrow
#

okey

#

i created

quartz apex
fathom burrow
quartz apex
#

wait until game.Loaded then use content provider to check whether object is loaded or not

fathom burrow
#

should i do it like this

quartz apex
#

?

quartz apex
fathom burrow
#

okey

fathom burrow
fathom burrow
#

its kinda complicated

fathom burrow