Currently my method is straight up math.random and that leads to multiple same player selects and that's seems to unfair to me.
1 | local canid = { } |
2 | for i,v in pairs (game.ReplicatedStorage.PlayerInfo:GetChildren()) do |
3 | table.insert(canid, v.Name) |
4 | v.PersonType.Value = "Survivor" |
5 | end |
6 | local hunter = canid [ math.random(#canid) ] |
7 | game.ReplicatedStorage.PlayerInfo.PlayerHolder:FindFirstChild(hunter).PersonType.Value = "Hunter" |
What I'm looking for is a way to select all players in a rotation. That way everyone has a chance to play as the Hunter. Is there any way to make that in lua?
1 | local alreadySelected = { } |
-- I wrote a function for you to check if the player was already selected:
1 | function check(player) |
2 | for i,v in pairs (alreadySelected) do |
3 | if v = = player then |
4 | return true |
5 | end |
6 | end |
7 | end |
-- now when selecting a hunter you will do
1 | if check(plr.Name) then |
2 | -- rechoose because player was already selected this rotation |
3 | else |
4 | table.insert(alreadySelected, plr.Name) |
5 | -- make player hunter |
6 | end |
now to know and reset the table when everyone has been a hunter you can just do
1 | if #Players = = #alreadySelected then |
2 | alreadySelected = { } -- this sets the table empty again |
3 | -- start rolling hunter again |
4 | end |
You'll also want to have a playerLeaving function and use table.remove() to remove the player from the table if he is in it, if you don't do this then if #Players == #alreadySelected then
will bug out and your table will never reset! If this helped, please mark this as the answer