Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

player argument must be a Player object. Help?

local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
print(randomPlayer)
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.

1 comment

0

Are you running this when the game starts? It's going to error if you do this.

2 answers

✓ Accepted answer

GetChildren would be the way to go for me, so something like this should be fine:

local Players = game.Players:GetChildren()
local RandomPlr = Players[math.random(1,#Players)]
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:

local PlayerArray = game.Players:GetPlayers()
local randplayer = PlayerArray[math.random(1,PlayerArray)]

If it doesn’t work, then:

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.

1 comment

0

Hello. Did this work? If it did, accept this answer. If not, tell me how I can modify it

This discussion is preserved as it was. New answers, comments, and votes are closed.