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

make a gui visible only for the players with their names written on the table?

Asked by 4 years ago

noob scripter but i want an admin script to only be visible to the players that are inside the table by accessing the Players, finding their names and putting a gui in their PlayerGui, i used the in pairs loop because thats the best way i know to do it, but i got nothing in the output and nothing works. (i am testing to see if it works by making it print "found", instead i get nothing)

01local admins = {"PicoTheRiko", "toxa_pas"}
02 
03local player = game.Players:GetChildren()
04 
05for i, v  in pairs(player) do
06    if v.Name == admins then
07        print("found")
08    else
09        print("not")
10    end
11end
0
Is ts a local or normal script? Also, where is it placed? User#32819 0 — 4y

2 answers

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

So, you were on the right track by using a pairs loop, but you weren't checking each entry of your "admins" table in it.

"if v.Name == admins then"

That line will try to compare each name to the table itself, which of course won't work for what you're trying to do.

Here's how I would implement it:

01local Players = game:GetService("Players")
02local adminList = {"PicoTheRiko", "toxa_pas"} -- I'd recommend using player's UserId's, as opposed to using their Username, because if they change their name then you'll have to update this list.
03 
04local function checkForAdmins()
05    local players = Players:GetPlayers()
06    for _, Player in pairs(players) do
07        local foundAdmin = false; -- used to track whether or not this Player is an admin
08        for _, admin in pairs(adminList) do
09            if Player.Name == admin then
10                foundAdmin = true
11                break -- breaks the admin loop
12            end
13        end
14        if foundAdmin then -- checks to see if the previous loop changed the foundAdmin bool at all
15            print(Player.Name .. " is an admin.")
View all 27 lines...
Ad
Log in to vote
0
Answered by 4 years ago

I think it's because you're not referrencing the table position, wich can be done like so:

1admins[1] -- position 1 wich is "PicoTheRiko"
2admins[2] -- position 2 wich is "toxa_pas"

So with that, we can make your script to print

01local admins = {"PicoTheRiko", "toxa_pas"}
02 
03local player = game.Players:GetChildren()
04 
05for i, v  in pairs(player) do
06    if v.Name == admins[1] or v.Name == admins[2] then
07        print("found")
08    else
09        print("not")
10    end
11end

Now, to make the gui appear, we can do it like so:

1local admins = {"PicoTheRiko", "toxa_pas"}
2 
3local player = game.Players:GetChildren()
4 
5for i, v  in pairs(player) do
6    if v.Name == admins[1] or v.Name == admins[2] then
7        game.Players.LocalPlayer:WaitForChild("screenGuiNameHere").Enabled = true
8    end
9end

Test it out, if it still doesn't work, you can do a loop with a wait() to run that script every few seconds.

0
does not work, nor does the loop PicoTheRiko 34 — 4y

Answer this question