Hey, I’m making a script that gives you a role depending on your team.
Currently there’s 3 teams (New Yeller, Really red and Navy blue). New Yeller and Really red teams work, and get their role given.
However when it comes to Navy blue, it doesn’t work properly. The code for the role given to the Navy blue team members checks if there’s anyone with the role “SCP-966” and if there is, rolls a number between 1 and 3, if it’s the number 2, then it returns “See No Evil”. Else, it returns “MTF”.
if team == BrickColor.new("Navy blue") then --checks if team is Navy blue
for i,v in pairs (game:GetService("Players"):GetChildren()) do --gets the players
if v:FindFirstChild("Role").Value == "SCP-966" then --if a player has the role "SCP-966"
local number = math.random(1,3) --rolls number between 1 and 3
if number == 2 then
return("See No Evil") --Returns "See No Evil"
end
else
return("MTF") --else it just returns "MTF"
end
end
end
The problem is: I go to test with 2 players, one player spawns in the Really red team and gets “SCP-966” role, the other spawns in the Navy blue team and always gets “MTF” role. Any help would really be appreciated.
If you want it to return “MTF” if the number isn’t 2 then add another else return “MTF” between return “See No Evil” and end because there isn’t already an else statement for that.
I added two print checks, one before the “if v:FindFirstChild(“Role”).Value…” part, and one after it. The print check before it gets printed, but the one after it doesn’t. So I suppose the problem is in the role check part of the code.
This is the code that gives a role to the players in the Really red team:
if team == BrickColor.new("Really red") then
for i,v in pairs (game:GetService("Players"):GetChildren()) do
local number = math.random(1,3)
if number == 1 then
rep:FindFirstChild("106").Script:Clone().Parent = player.Backpack
rep:FindFirstChild("106").Arm:Clone().Parent = player.Backpack
return("SCP-106")
end
if number == 2 then
rep:FindFirstChild("457").Script:Clone().Parent = player.Backpack
rep:FindFirstChild("457").Arm:Clone().Parent = player.Backpack
return("SCP-457")
end
if number == 3 then
return("SCP-966")
end
end
end
There’s no problem with this part of code though. Whenever a character spawns and their role is given, there’s a GUI telling them their role, and it displays the correct role. I even check in Explorer and it is correct.
Err, no. Players in the Navy blue team don’t get the SCP-966 role. Players in the Really red team do, though.
The code checks if there is anybody with the SCP-966 role (so a player in the Really red team could have the SCP-966 role). If there is, then it would roll a number between 1 and 3. And if the number is 2, then they would get the “See No Evil” role.
Edit: I think I could have misunderstood what you meant. The player in the Navy blue team spawns after the player with in the SCP team gets the SCP-966 role.
Uh I think I maybe found it.
You want to get all the players and loop all of them until you get one player with SCP - 966 role and then do the rest of the code. The problem is you check if first player has the role and if he doesn’t then it returns MTF. So it doesn’t loop all the players, instead if player 1 doesn’t have the role, script just returns MTF instead of checking next player. Just remove the last else return “MTF” check and the script should work.