I'm unable to get my script to load all the players in the server. I'm pretty sure it's because I'm not defining the players right. Can someone help me define the players?
Code:
player = game.players while true do wait(60) player:LoadCharacter() end
There are a few things wrong with this code. First of all, "players" does not exist. It's "Players". As a matter of fact, it is recommended to use :GetService
as well. Also, use local variables (For example: "local x = 5"). You also cannot load the character of the Players service, as it is not an actual player instance. To combat this, you should loop through all of the player's in Players by using a for
loop. However, you can only loop through tables, so you should use :GetPlayers
as it returns a table. In a scenario in which you aren't looping through the players in Players or the players in a team, you would use :GetChildren
instead, as it also returns a table.
Here is the final product:
local players = game:GetService("Players") while true do wait(60) for _, player in pairs(players:GetPlayers()) do player:LoadCharacter() end end
I'll fix up the code for you:
local Players = game.Players while true do wait(60) for i,v in pairs(Players:GetPlayers()) do v:LoadCharacter() end end