Where is the location of the player?

Hey guys! I have some problems with my script… I need the script location for the random player… game.Players.[Player] … I want to know what to add in the [ Player ] place for the random player or all players…

Could try something like

game.Players:GetChildren()[math.random(1, #game.Players:GetChildren())]

So if you need the location of a random player, you could try

local RandomPlayerCFrame = game.Players:GetChildren()[math.random(1, #game.Players:GetChildren())].Character.PrimaryPart.CFrame
2 Likes

game.Players:GetChildren() (or you could also use game.Players:GetPlayers()) returns a table
containing all the player in the game. Then using the math.random, you can generate a random index from 1 (since tables start at 1), and #game.Players:GetPlayers() (notice that # operator) which is how many players there are in total, in other words the size of table that game.Players:GetPlayers() returns.

generaterandotbl

Than put that randomly generated index like this

local random = game.Players:GetChildren()[math.random(1, #game.Players:GetChildren())]
1 Like