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)

local admins = {"PicoTheRiko", "toxa_pas"} 

local player = game.Players:GetChildren()

for i, v  in pairs(player) do
    if v.Name == admins then
        print("found")
    else
        print("not")
    end
end

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:


local Players = game:GetService("Players") local 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. local function checkForAdmins() local players = Players:GetPlayers() for _, Player in pairs(players) do local foundAdmin = false; -- used to track whether or not this Player is an admin for _, admin in pairs(adminList) do if Player.Name == admin then foundAdmin = true break -- breaks the admin loop end end if foundAdmin then -- checks to see if the previous loop changed the foundAdmin bool at all print(Player.Name .. " is an admin.") -- add the function that will show the admin only stuff here else print(Player.Name .. " is not an admin.") -- add the function that will hide the admin only stuff here end end end while true do -- will run our checkForAdmins function every 3 seconds. wait(3) checkForAdmins() end
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:

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

So with that, we can make your script to print

local admins = {"PicoTheRiko", "toxa_pas"} 

local player = game.Players:GetChildren()

for i, v  in pairs(player) do
    if v.Name == admins[1] or v.Name == admins[2] then
        print("found")
    else
        print("not")
    end
end

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

local admins = {"PicoTheRiko", "toxa_pas"} 

local player = game.Players:GetChildren()

for i, v  in pairs(player) do
    if v.Name == admins[1] or v.Name == admins[2] then
        game.Players.LocalPlayer:WaitForChild("screenGuiNameHere").Enabled = true
    end
end

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