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

I am trying to make a gui show only to specific people, and don't know how to?

Asked by 4 years ago
Edited 4 years ago

I have no clue how to do it and was experimenting so see if it will work. My script doesn't work, and I am sure most of it doesn't exist. Here is my code.

script.Parent.Visible = false
local Admins = {"Sadwowow21"}
if Player.name == Admins then
    script.Parent.Visible = true
end

2 answers

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

So what I would do is create a Dictionary (which is basically an array but each index [or value] is assigned a value).

Let me demonstrate:

local Player = game.Players.LocalPlayer;
local dictionary = {
    Admin1 = true,
    Admin2 = true
};

print(dictionary["Admin1"]); -- true

Why this is better is because now, you can set different people to have different "staff" levels.

local Player = game.Players.LocalPlayer;
local dictionary = {
    Username1 = "Administrator",
    Username2 = "Moderator"
};

print(dictionary["Username1"]); -- "Administrator"

So, how do you implement this into your script?

local Player = game.Players.LocalPlayer;
script.Parent.Visible = false;
local Admins = {
    Sadwowow21 = true,
    -- Add more names, and set them to true
};
if Admins[Player.Name] then
    script.Parent.Visible = true;
end

If you further wanted to add more and have it only show for Administrators:

local Player = game.Players.LocalPlayer;
script.Parent.Visible = false;
local Admins = {
    Sadwowow21 = "Administrator",
    TestUser = "Moderator"
    -- Add more names, and set them to true
};

if Admins[Player.Name] == "Administrator" then -- Even though TestUser is in the dictionary, they are ignored because they are set as a "Moderator" and not an "Administrator", which is what we looked for with this line.
    script.Parent.Visible = true;
end
0
thank you, but it isn't showing still Sadwowow21 57 — 4y
0
I just tested it, and it did work. Which one are you using? If you don't want to get into dictionaries, I'd recommend looping, as Filipalla answered. GeneratedScript 740 — 4y
0
Edit: The reason it's not working is because you need to use a LocalScript. You need to have the LocalScript inside the GUI. Then try again. GeneratedScript 740 — 4y
0
ok Sadwowow21 57 — 4y
View all comments (9 more)
0
I keep getting this warning sign 18:19:28.744 - Players.SadWowow21.PlayerGui.ScreenGui.TextButton.LocalScript:6: attempt to index global 'Player' (a nil value) Sadwowow21 57 — 4y
1
ah so you never declared LocalPlayer? Okay, I'll update the answer. GeneratedScript 740 — 4y
0
I updated it so it'll work. GeneratedScript 740 — 4y
0
oh thx so much Sadwowow21 57 — 4y
0
If it worked, can you please mark it as answer? Thanks. GeneratedScript 740 — 4y
0
Oof, He Didn't Do That :/ Isn't That Against The Rules? (I'm Not Going To Report Him Or Anything Like That, Just Asking) fff054 51 — 4y
0
I don't know lol. GeneratedScript 740 — 4y
0
??? Sadwowow21 57 — 4y
0
Thanks Sadwowow21. GeneratedScript 740 — 4y
Ad
Log in to vote
0
Answered by
Filipalla 504 Moderation Voter
4 years ago

You are trying to compare a string with a table, what you actually want to do is get the strings in the table like so

script.Parent.Visible = false
local Admins = {"Sadwowow21"}
for _, Admin in pairs(Admins) do
    if Player.Name == Admin then
        script.Parent.Visible = true
    end
end

Note: Using the UserID is probably better for this

0
would it be a normal script or local script? because I am using normal script and it isn't showing Sadwowow21 57 — 4y

Answer this question