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

GUI that should only appear for admins when they join appears for everyone after death?

Asked by 4 years ago

Heya. I have a GUI that should appear for admins when they join, however, it also appears for non-admins when they die. Now, there's nothing special in the GUI, but I'd still like to fix this.

local admins = {
    "Player1";
    "Player2";
    "Player3";
    "Player4"
}

local function isAdmin(player)
    for _, v in pairs(admins) do
        if v == player.Name then
            return true
        end
    end

    return false
end

local Players = game:GetService("Players")
local AW = game.StarterGui.AdminWelcome.Gradient

Players.PlayerAdded:Connect(function(player)
    if isAdmin(player) then
        AW.Visible = true
    else
        AW.Visible = false
    end
end)

Any help is appreciated.

0
change line 22 to "if isAdmin(player) == true then" because if you don't write true then it means it's not nill kingblaze_1000 359 — 4y

1 answer

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

The problem

You are writing if isAdmin(player) then which means if isAdmin(player) is not equal to nil then it will go ahead.

Solution

You must write if isAdmin(player) == true then which is being precise to what the result is.

local admins = {
    "Player1";
    "Player2";
    "Player3";
    "Player4"
}

local function isAdmin(player)
    for _, v in pairs(admins) do
        if v == player.Name then
            return true
        end
    end

    return false
end

local Players = game:GetService("Players")
local AW = game.StarterGui.AdminWelcome.Gradient

Players.PlayerAdded:Connect(function(player)
    if isAdmin(player) == true then --//This is the change
        AW.Visible = true
    else
        AW.Visible = false
    end
end)

I'm not sure if this helped but I hope it did! Make sure to accept the answer if it worked perfectly. Any problems reply to this answer and I'll try to change it.

0
Thank you so much! ItzTacoTimee 6 — 4y
0
No problem! I'm glad to hear it worked!! kingblaze_1000 359 — 4y
Ad

Answer this question