Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

player argument must be a Player object. Help?

Asked by 4 years ago
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.

0
Are you running this when the game starts? It's going to error if you do this. royaltoe 5144 — 4y

2 answers

Log in to vote
0
Answered by
TopBagon 109
4 years ago

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.

Ad
Log in to vote
0
Answered by 4 years ago

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.

0
Hello. Did this work? If it did, accept this answer. If not, tell me how I can modify it sahadeed 87 — 4y

Answer this question