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

I don't understand why its not working, trying to make it pick a random player?

Asked by 6 years ago

I don't understand why its not working, trying to make it pick a random player from Players and making the Value "Asking" true

local QuestionParts = game.Workspace.QuestionParts
local TotallyNotRemotes = game.ReplicatedStorage.TotallyNotRemotes
local AskGui = game.Lighting
local ServerGui = game.Lighting


game.Players.PlayerAdded:connect(function(player)


function chooserandom()
 local players = game.Players:GetChilderen()
 print (#players)
 if #players > 2 then
  local RandomPlayer = players[math.random(1,#players)]

    RandomPlayer.Asking.Value = true


chooserandom()

 end
end

end)

1 answer

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago
Edited 6 years ago

How exactly are you figuring this will work? You are calling "chooserandom" inside the function "chooserandom". Your code should be like this. Just eddited the structure a bit.

local QuestionParts = game.Workspace.QuestionParts
local TotallyNotRemotes = game.ReplicatedStorage.TotallyNotRemotes
local AskGui = game.Lighting
local ServerGui = game.Lighting

function chooserandom()
 local players = game.Players:GetChilderen()
 print (#players)
 if #players > 2 then
  local RandomPlayer = players[math.random(1,#players)]

    RandomPlayer.Asking.Value = true



 end
end

game.Players.PlayerAdded:connect(function()
    chooserandom()
end)



Ad

Answer this question