Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago

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)
0
You're comparing the player's name to the table 'Admin,' and incorrectly spelt 'Name' on line 12 (lua is case-sensitive.) :P TheeDeathCaster 2368 — 7y
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? NextYearStudios 46 — 7y
1
Well, to simply create dictionaries is one way: http://wiki.roblox.com/index.php?title=Table#Dictionaries Literally lol. TheeDeathCaster 2368 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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)
Ad

Answer this question