I have this script that is supposed to assign every player to a random array/table. The first three players should be assigned to the "Werewolves" table, while the rest is completely random. Why is no player being assigned to any role? (Note: The script did assign the players randomly and it worked before adding that "if Werewolfcount >=") Dont get intimidated by the size, its pretty much the same script repeated and slightly changed:
local Players = game:GetService("Players")
local Roles = game.ReplicatedStorage.roles:GetChildren()
Villagers = {}
Werewolves ={}
Arsonists = {}
Hunters ={}
Mediums ={}
Seers ={}
Jesters ={}
Witches ={}
Minimumwolves = 3
Werewolvescount = table.getn(Werewolves)
MaximumSeers = 1
MaximumArsonists = 1
MaximumJesters = 1
game.Players.PlayerAdded:Connect(function(plr)
local NeedsRole = Instance.new("BoolValue")
NeedsRole.Name = ("NeedsRole")
NeedsRole.Parent = plr
NeedsRole.Value = true
print("Just joined: "..plr.Name)
if table.getn(Players:GetChildren()) == 4
then
print("There are "..table.getn(Players:GetChildren()).." Players, choosing Roles!")
wait(1)
print("...Choosing...")
wait(3)
for _,player in pairs(Players:GetChildren())
do
local ChooseTable = math.random(1,8)
player.NeedsRole.Value = true
if ChooseTable == 1 and Werewolvescount >= 3
then
if player.NeedsRole.Value == true
then
table.insert(Villagers,1,player)
player.NeedsRole.Value = false
else
if Werewolvescount <3 then
table.insert(Werewolves,1,player)
end
print(player.Name.." already has a role!")
end
elseif ChooseTable == 2 and Werewolvescount >= 3
then
if player.NeedsRole.Value == true
then
table.insert(Werewolves,1,player)
player.NeedsRole.Value = false
else
if Werewolvescount <3 then
table.insert(Werewolves,1,player)
end
print(player.Name.." already has a role!")
end
elseif ChooseTable == 3 and Werewolvescount >= 3
then
if player.NeedsRole.Value == true
then
table.insert(Arsonists,1,player)
player.NeedsRole.Value = false
else
if Werewolvescount <3 then
table.insert(Werewolves,1,player)
end
print(player.Name.." already has a role!")
end
elseif ChooseTable == 4 and Werewolvescount >= 3
then
if player.NeedsRole.Value == true
then
table.insert(Hunters,1,player)
player.NeedsRole.Value = false
else
if Werewolvescount <3 then
table.insert(Werewolves,1,player)
end
print(player.Name.." already has a role!")
end
elseif ChooseTable == 5 and Werewolvescount >= 3
then
if player.NeedsRole.Value == true
then
table.insert(Mediums,1,player)
player.NeedsRole.Value = false
else
if Werewolvescount <3 then
table.insert(Werewolves,1,player)
end
print(player.Name.." already has a role!")
end
elseif ChooseTable == 6 and Werewolvescount >= 3
then
if player.NeedsRole.Value == true
then
table.insert(Seers,1,player)
player.NeedsRole.Value = false
else
if Werewolvescount <3 then
table.insert(Werewolves,1,player)
end
print(player.Name.." already has a role!")
end
elseif ChooseTable == 7 and Werewolvescount >= 3
then
if player.NeedsRole.Value == true
then
table.insert(Jesters,1,player)
player.NeedsRole.Value = false
else
if Werewolvescount <3 then
table.insert(Werewolves,1,player)
end
print(player.Name.." already has a role!")
end
elseif ChooseTable == 8 and Werewolvescount >= 3
then
if player.NeedsRole.Value == true
then
table.insert(Witches,1,player)
player.NeedsRole.Value = false
else
if Werewolvescount <3 then
table.insert(Werewolves,1,player)
end
print(player.Name.." already has a role!")
end
end
end
print("")
print("ROLETABLES AFTER ASSIGNMENT!:")
print("")
print("Villagers: ")
print(#Villagers)
wait(1)
print("Werewolves: ")
print(#Werewolves)
wait(1)
print("Arsonists: ")
print(#Arsonists)
wait(1)
print("Hunters: ")
print(#Hunters)
wait(1)
print("Mediums: ")
print(#Mediums)
wait(1)
print("Seers: ")
print(#Seers)
wait(1)
print("Jesters: ")
print(#Jesters)
wait(1)
print("Witches: ")
print(#Witches)
else
print("Not enough players!")
end
end)

1 comment
I did what you said and nothing changed. Same results. Also, i would be very thankful if you could help me rewrite the code!