#pick a player function not working

1 messages · Page 1 of 1 (latest)

half lake
#

so i have this script which executes a function when you click a button.
it is supposed to pick a random player from the server, and change a text label gui to that players username. but when i tested it (with 2 other players in the server), it didn't work and kept displaying my own username instead.

after that i changed
game.Players:GetChildren() to game.Players:GetPlayers()

will this fix it or not? and if not, why is it not working correctly. just focus on the section of the script where it picks a player and changes the text label.

cinder plover
#

local allPlayers = game:GetService("Players"):GetPlayers()
local selectedPlayer = allPlayers[math.random(1, #allPlayers)]