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

Owner gui script showing for everyone instead of certain player. How do i fix it?

Asked by 4 years ago

This script is placed inside a screengui, so is the textbutton. The problem with this script is that it's not working at all (also, there are no errors in the output), everyone can see the text button (even though the property of being visible is disabled).

if game.Players.LocalPlayer.Name == "Player1" or "YoBoi1337" then
script.Parent.TextButton.Visible = true
else
script.Parent.TextButton.Visible = false
end

1 answer

Log in to vote
0
Answered by
Mr_Unlucky 1085 Moderation Voter
4 years ago
Edited 4 years ago
local AuthorizedPlayers = {291900436}

local Player = game:GetService("Players").LocalPlayer

function checkPlayer()
    for i,v in pairs(AuthorizedPlayers) do
        if Player.UserId == v then
            return true
        end
    end

    return false
end

local isAuthorized = checkPlayer()

if isAuthorized == true then
    script.Parent.Enabled = true
else
    --The ScreenGui's enabled property stays as false.
end

We have a table called AuthorizedPlayers that contains a bunch of userIds. We have a variable for the localplayer. We run checkplayer, which is a function that loops through the table AuthorizedPlayers to see if the userId is in the table. If that is the case we return true. If not, we return false. We run the function using the variable and if it returns as true we enable the screengui, if not, we do nothing since the screen gui should have the enabled property false beforehand.

Ad

Answer this question