#How can i run a code after all players are loaded ?
1 messages · Page 1 of 1 (latest)
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
ok should i put it on startercharacter ?
starterplayer
okey
thanks ill try it
so there wont be a problem beacuse some times the players that join will be 4 and sometimes 2
game.Loaded:Wait()
LoadedEvent:Fire()
game.Players.PlayerAdded:Connect(function(player)
print("There are", #game.Players:GetPlayers(), "players in the game")
end)
where should i put it ?
okey thanks
it can go in workspace, replicatedfirst, serverscriptservice, starterplayerscripts, startergui
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)
nice
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.
This is something up to developer
ok
i made a script in serverscript service to know when a player has joined the server
i should do a local script on starterplayerscript to know when a player has loaded ?
and then call the function for the part to move ?
Replicated First
Ya
Remote event
game.Loaded event will work
wait until game.Loaded then use content provider to check whether object is loaded or not
should i do it like this
on the local script ?
?
Ya
okey
how do i use the content provider ?
its kinda complicated