Im making a freeze tag game and I need help scripting where 5 random players with a bool value(already scripted it to go in everyplayer) to be set true when I call a function and to be inserted into a table called taggers. Any ideas?
✓ ANSWER ACCEPTED
How do i choose random taggers?
2 answers
✓ Accepted answer
Hey dude, remember me? Lol, anyways I think I can help you. Try doing something like this:
taggers={}
function SetPlayers()
taggers={} --Empties the table so it can be set to new players.
repeat
Set=true
Players=game.Players:GetPlayers()
NewTagger=Players[math.random(1,#Players)]
for i==1,#taggers do
if taggers[i]==NewTagger then
Set=false
end
end
if Set==true then --Makes sure it's not the same player
taggers[#taggers+1]=NewTagger
NewTagger.Bool.Value=true --Change this to the name of the BoolValue inside the player
end
until #taggers==5 --Assures that there are 5 taggers.
end
SetPlayers()
Ok, well this should work with a little tweaks if you want. Hope I helped :P -Sorry I forgot some of it the first time. It should be fixed now.
I don't know if this'll work:
taggers = {}
for i = 1,5 do
repeat
local done = 0
local t = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
for j,v in pairs(taggers)do
if t == v then
done = 1
end
end
if done == 0 then table.insert(taggers,t) end
until #taggers == i
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Thx m8!
No prob :P