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

The GUI destroys itself even when your name is in the value, what do I do?

Asked by 4 years ago
Edited 4 years ago

I have no idea what i'm doing wrong but I am trying to make it so it doesn't destroy the gui if your name is in the admins table. How do I do this? Please use answers so I can reward you if your comment helped!

-----------Variables-----------
admins = {"MillerrIAm",""}
name = game.Players.LocalPlayer.Name
-----------Main Code-----------
if name == admins then
    wait()
else 
    script.Parent:Destroy()
end

Thank you in advance!

2 answers

Log in to vote
1
Answered by
sleazel 1287 Moderation Voter
4 years ago

Admins is a table, so your if statement will be always false. Use dictionary instead:

-----------Variables-----------
admins = {
    ["MillerrIAm"] = true,
    ["Sleazel"] = true, --just joking, remove that line :) But that is how you add more admins
    }
name = game.Players.LocalPlayer.Name
-----------Main Code-----------
if admins[name] then
    wait()
else 
    script.Parent:Destroy()
end

BTW, make sure you check for admin privileges on server as well, otherwise it is a disaster waiting to happen.

0
How would I do that? Just2Terrify 566 — 4y
0
I have a question for you, is there a way I can se this to make it into a server script where it cant be effected by exploiters? Just2Terrify 566 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You need to loop through the table to check if any of the values match your players name, shown below.

admins = {"metalive"}
player = game.Players.LocalPlayer
function checkWhitelist(playerName)
    local whitelisted = false
    for i,name in pairs(admins)do
        if playerName == name then
            whitelisted = true
        end
    end
    return whitelisted
end

if checkWhitelist(player.Name) then
    print("Whitelisted")
else
    print("Player is not whitelisted")
end

If you want to remove the GUI before it's loaded for the player then it needs to be in a server script. If you want to remove the GUI when the player joins then:

admins = {"metalive"}

function checkWhitelist(playerName)
    local whitelisted = false
    for i,name in pairs(admins)do
        if playerName == name then
            whitelisted = true
        end
    end
    return whitelisted
end

game.Players.PlayerAdded:Connect(function(player)
    if checkWhitelist(player.Name) then
        print("Whitelisted")
    else
        local Ss, err = pcall(function()
            local playerGui = player:WaitForChild("PlayerGui")
            local gui = playerGui:WaitForChild("gui")
            gui:Destroy()
        end)
        if Ss then
            print("Gui removed")
        else
            warn(err)
        end
    end
end)

0
your script did not work, i tried everything you said. it didn't work. Just2Terrify 566 — 4y
0
Working perfectly for me so you're doing something wrong on your end. metalive 0 — 4y
0
my guy, i did everything exactly as you said.. there's not much I can do for your stuff. Just2Terrify 566 — 4y

Answer this question