Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

this script isn't detecting if the player's name is in the admin table?

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)

3 comments

0

You're comparing the player's name to the table 'Admin,' and incorrectly spelt 'Name' on line 12 (lua is case-sensitive.) :P

0

updated the error on line 12, and how would I make it filter through the admin table to see if the name is on the list?

1

Well, to simply create dictionaries is one way: http://wiki.roblox.com/index.php?title=Table#Dictionaries Literally lol.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.