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

How can I prevent certain players from being added to this table?

Asked by 4 years ago

I made this script so that I can lock all players in the server from using a certain gui. It can only be activated by players with a numbervalue (defined as "Rank") that has a value of 999 (developers). It works, but it can't be undone unless you keep the gui up because literally everyoen loses the abiltity to open the gui. I want to make an exception for players whose stored numbervalue ("Rank") is 999 so that their gui doesn't disappear. Any help is welcome :)

Here is the script (It is a server script):

local AlreadyActive = false

function activate()
    local player = script.Parent.Parent.Parent.Parent.Parent.Parent
    local Rank = player:WaitForChild('Rank')
    if player.Rank.Value == 999 and AlreadyActive == false then -- This checks that the person running the command has a rank of 999.
        AlreadyActive = true
        local gamers = game.Players:GetChildren() -- This is the table that adds all the players
        for i, v in pairs(gamers) do
            v.PlayerGui.trollGui.Open.Visible = false
        end
        game.StarterGui.trollGui.Open.Visible = false
    elseif player.Rank.Value == 999 and AlreadyActive == true then
        AlreadyActive = false
        local sadgamers = game.Players:GetChildren()
        for i, v in pairs(sadgamers) do
            v.PlayerGui.trollGui.Open.Visible = true
        end
        game.StarterGui.trollGui.Open.Visible = true
    end
end

script.Parent.MouseButton1Click:Connect(activate)

Answer this question