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

Random player chooser only works in Studio, how can I fix this?

Asked by 5 years ago

I have a random player chooser script and basically, it will choose a random player and give him clothes and place him on a team. It worked fine in Studio but now it's gone to shreds, nothing is working. Here is the script:

wait(0.1)
local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
randomPlayer.TeamColor = BrickColor.new("Really black")

Any ideas on how I an fix this?

0
I don't see a problem. How did the script work in Studio? Pojoto 329 — 5y
0
It waited less than a second and put me on the team I specified since I didn't have anyone else. I tried it on the actual game and nothing happens, nothing appears in the console or anything. I tried remaking it and it worked fine in Studio, but yet again failed to work on the actual game. TrixitesWasTaken 13 — 5y

2 answers

Log in to vote
0
Answered by
aazkao 787 Moderation Voter
5 years ago
Edited 5 years ago

Nothing is happening in the actual game because line 2 will execute immediately when the game starts, however the player doesnt get addedd into the game that fast,so it will get nothing and the script will end, so what you can do is use a game.Players.PlayerAdded event listener and assign your player's teams in this listener

game.Players.PlayerAdded:Connect(function(plr)
    game.Workspace:WaitForChild(plr.Name)--this is to make sure he spawns first, this is optional
local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
randomPlayer.TeamColor = BrickColor.new("Deep orange")
end)


Ad
Log in to vote
-2
Answered by 5 years ago

Try using Remote Functions.

0
This could've been a comment... Pojoto 329 — 5y
0
Does it matter CarlPlandog 20 — 5y
0
yes User#19524 175 — 5y
0
Get over it CarlPlandog 20 — 5y

Answer this question