1 | local randomPlayer = game.Players:GetPlayers() [ math.random( 1 ,#game.Players:GetPlayers()) ] |
2 | print (randomPlayer) |
3 | game.ReplicatedStorage.Talk:FireClient(randomPlayer, "Why the hecc are we all going to the bathroom at the same time!" ) |
It says that player argument must be a Player object but I checked other sources dozens of times and found the same script/method. Please help! I know that it is nil but i don't quite know why because I'm pretty sure I did everything correctly.
GetChildren
would be the way to go for me, so something like this should be fine:
1 | local Players = game.Players:GetChildren() |
2 | local RandomPlr = Players [ math.random( 1 ,#Players) ] |
3 | print (RandomPlr.Name) -- I think you were trying to print the name which you need to define... |
Hope this worked.
Try making an earlier variable and test. Maybe roblox does not like turning a function straight into an array:
1 | local PlayerArray = game.Players:GetPlayers() |
2 | local randplayer = PlayerArray [ math.random( 1 ,PlayerArray) ] |
If it doesn’t work, then:
1 | local randplayerobject = game.Players:FindFirstChild(randplayer) |
I dont know if GetPlayers returns objects or strings. But one thing I do know is that I don’t have access to my pc rn so i can not test.