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

my whitelisting system isnt working?

Asked by 4 years ago

for some reason my whitelisting system which i will use for an admin gui wont work, any advice on how to fix it?

Whitelist = {   
    "mateja1119",
    "Player1"
    }

game.Players.PlayerAdded:Connect(function(plr)
    for i,v in ipairs(Whitelist) do
    if v.Name == Whitelist then
            local mercuryclone = script.Mercury:Clone()
            mercuryclone.Parent = game.Players:WaitForChild(v.Name).PlayerGUI
            mercuryclone.Name = "GUI"
            mercuryclone.Frame.Visible = true
    end
    end 
end)
0
try plr.Name instead of v.Name Arkrei 389 — 4y
0
Needs to be `if plr.Name == v` fredfishy 833 — 4y

2 answers

Log in to vote
1
Answered by
JakyeRU 637 Moderation Voter
4 years ago
Edited 4 years ago

Hello.

To access information in a table you do: TableName[Information] It will return false if the information is not in the table, if it is, it will return its value. Here is a simple whitelist script.

local AllowedPlayers = {
    ["PlayerName1"] = true,
    ["PlayerName2"] = true,
    ["PlayerName3"] = true,
    ["PlayerName4"] = true
}

game.Players.PlayerAdded:Connect(function(player)
    if not AllowedPlayers[player.Name] then
        player:Kick("You are not allowed to join this game!")
    end
end)

-- In your case, check if the player is in the table.

game.Players.PlayerAdded:Connect(function(player)
    if AllowedPlayers[player.Name] then
        -- Do Stuff
    end
end)

Anyways, you can do this in multiple ways. Here's your fixed code:

local Players = {"JakyeRU", "ABC", "DDCDS"}

game.Players.PlayerAdded:Connect(function(player)
    for _, v in pairs(Players) do
        if player.Name == v then
            -- Do stuff
        end
    end
end)

What was wrong with your code? You checked (if PlayerName == Table) which is not correct. The v will become the element in the table. The for loop will repeat 3 times. v will be JakyeRU, ABC, and DDCDS. That's why you do (if playerName == v) or (if v == PlayerName). You compare 2 strings.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Im SO GOOD AT SCRIPTING but heres one thing i dont know, i dont understand what pairs are, so i cant do that, but i still want to help u, so ill just put a script that may take a LITTLE longer but should work- Instead of this:

Whitelist = {   
    "mateja1119",
    "Player1"
    }

game.Players.PlayerAdded:Connect(function(plr)
    for i,v in ipairs(Whitelist) do
    if v.Name == Whitelist then
            local mercuryclone = script.Mercury:Clone()
            mercuryclone.Parent = game.Players:WaitForChild(v.Name).PlayerGUI
            mercuryclone.Name = "GUI"
            mercuryclone.Frame.Visible = true
    end
    end 
end)

Try This:

game.Players.PlayerAdded:Connect(function(plr)
  if plr.Name == "mateja1119" or "Player1" or "Player2" or "anything" then
            local mercuryclone = script.Mercury:Clone()
            mercuryclone.Parent = game.Players:WaitForChild(plr).PlayerGui
            plr.PlayerGui.Mercury.Name = "GUI"
    wait()
            plr.PlayerGui.GUI.Frame.Visible = true
    end
end)

and just to make sure saying mercuryclone after the clone is in the player doesn tcause problems, i changed that alittle

Answer this question