So this script changes your team when you walk over the spawn location but I have it detect if the team is "StaffOnly" and then detect if you're an admin/staff but it doesn't seem to be working even if Player1 is on the Admin Table. I don't really know what I'm doing wrong.
local Admin = {"Player1","NextYearStudios"} script.Parent.Touched:connect(function(part) local character = part.Parent local player = game.Players:GetPlayerFromCharacter(character) if player.TeamColor == script.Parent.TeamColor then return else for _,i in pairs (game.Teams:GetTeams()) do if i.TeamColor == script.Parent.TeamColor then if i.Folder_TeamStats.StaffOnly.Value == true then if player.Name == Admin then player.Team = i else return end elseif i.Folder_TeamStats.StaffOnly.Value == false then player.Team = i print(player.Team) print(player.TeamColor) end end end end end)
There are a number of ways to do this, but this is the way I generally do it.
The extra If statements aren't needed, and you should learn to use and
. You should also learn to use not
. They're both really useful.
local Admin = {"Player1","NextYearStudios"} script.Parent.Touched:connect(function(part) local char = part.Parent local player = game.Players:GetPlayerFromCharacter(char) for _,v in pairs(Admin) do -- This will loop through the admin table if player.Name == v then -- If the player's name is equal to any of the values in the table player.TeamColor = BrickColor.new("Admin Color") -- Change their team to the admin team else player.TeamColor = BrickColor.new("Other Color") -- Otherwise, change their team to whatever end end print(player.Team) print(player.TeamColor) end)