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

[S] How would I fix this script that makes sure the same player doesn't get picked twice in a row?

Asked by
LawlR 182
5 years ago
Edited 5 years ago
local function PickingPlayerToBeZombie()
            wait(.1)
            for i,v in pairs(Players) do --Players is a table, not game.Players:GetChildren()
                local position = 0
                position = position+1
                if v == ChosenPlayerToBeZombie then --v = chosen player
                    for i,q in pairs(ZombiesLastRound) do --q = player who was zombie last round
                        if q ~= v then
                            print(q)
                            print(v)
                            table.remove(Players,position)
                            position = position-1
                            for i=1,#ZombiesLastRound do
                                table.remove(ZombiesLastRound,i)
                            end
                            table.insert(ZombiesLastRound, v)
                        else
                            print("picking another player")
                            PickingPlayerToBeZombie()
                        end
                    end
                end
            end
        end

What I think is wrong with this is that when q == v then it runs the function on a loop since it picks from the 'Players' table, and it always picks the first item in that table. So how would I make it so that if q == v, then the next time the function runs, it starts at a different position from the 'Players' table. Sorry, this is kinda hard to explain. This might not even be the problem, but I can't see what else it could be.

0
If there is only one zombie per round, why are you using a table? You can just have a variable and define it later as the player who was chosen to be the zombie. lunatic5 409 — 5y
0
Or, if you really wanted to, you could use teams and set the zombie's team to a specific team (only for the zombie). You can then loop through the players, and if the player isn't on the zombie team, then set their team to the zombie team. Then set the previous zombie's team back to whatever other team you'd like, for example, Neutral, Spectators, Lobby, etc. lunatic5 409 — 5y
0
It could be one zombie, or it could be more. The more players there are in the game, the more players will be chosen to be zombies. LawlR 182 — 5y
0
I don't quite understand what you mean in your second comment. Change random players' team to zombies, then swap them with the players that aren't on the zombie team? I'm not sure how that would fix my problem. LawlR 182 — 5y
View all comments (4 more)
0
Ah, I see what you mean. I was thinking there could only be one zombie. Since that isn't the case, however, my previous comments won't be of much help. lunatic5 409 — 5y
0
It's fine, I found a way to randomise the positions of the table contents. However that broke a thing which prevented the same player to get picked twice or more, resulting in less zombies. I'm working on that now. LawlR 182 — 5y
0
USE A NESTED LOOOOOOOOOOOOOOP greatneil80 2647 — 5y
0
Never mind, I got the table randomising to work. LawlR 182 — 5y

Answer this question