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

I made three top bar icons, and I want them to show up for only certain players?

Asked by 2 years ago

local Players = game:GetService("Players")

-- Whitelisted players local DeveloperWhitelist = {"Arctemii", "Solar_Developer", "wedoalittletrollingB", "Cypouka", "Resemption_Zero"} local ModerationWhitelist = {"Arctemi", "LostInfamy", "Darcup", "Bidofity"} local TesterWhitelist = {"Arctemi", "AndyROCKY78", "awrjosip8",}

-- Other local TopScript = script.Parent local OtherScript = game:GetService("StarterGui").TopBar

-- Whitelist Funcations Players.PlayerAdded:Connect(function (player) if not table.find(DeveloperWhitelist, player.Name) then TopScript:Destroy() OtherScript.Disabled = true end end)

Players.PlayerAdded:Connect(function (player) if not table.find(ModerationWhitelist, player.Name) then TopScript:Destroy() OtherScript.Disabled = true end end)

Players.PlayerAdded:Connect(function (player) if not table.find(TesterWhitelist, player.Name) then TopScript:Destroy() OtherScript.Disabled = true end

1 answer

Log in to vote
0
Answered by 2 years ago

Hello,

This is a article on the problem you are facing so i hope this helps,

Tutorial

First of all, you have to Parent the Gui in Replicated storage, this will help in case of script failure or errors. Make all of your scripts in ServerScriptService as the most protected from hackers and exploiters. Make a script in ServerScriptService with the reference of your Gui, you can obtain this by,

Code Example, Reference to Gui


local Gui = game.ReplicatedStorage.TopBar  <---

Next, Make your Player Table with all of the Players

Code Example, Adding Player Table


local Gui = game.ReplicatedStorage.TopBar  

local PlayersTable = {"Roblox","BuilderMan"}  <---

We will now Connect a function with a Player.Added Event

Code Example, Player.Added & functions


local Gui = game.ReplicatedStorage.TopBar  

local PlayersTable = {"Roblox","BuilderMan"}

game.Players.PlayerAdded:Connect(function()  <---
    -- We will Add script here
end)  <---

Now we will add the Player Parameter. Roblox on default provides us the Player Parameter in the function Parameter,

Code Example, Adding Player Parameter


local Gui = game.ReplicatedStorage.TopBar  

local PlayersTable = {"Roblox","BuilderMan"}

game.Players.PlayerAdded:Connect(function(Player) <---
    -- We will Add script here
end)

To check if the new Player is in the Players Table what we can is run it in a pairs loop like the code example below

Code Example, Looping through Table


local Gui = game.ReplicatedStorage.TopBar  

local PlayersTable = {"Roblox","BuilderMan"}

game.Players.PlayerAdded:Connect(function(Player) 
    for _,Plr in pairs(PlayersTable) do  <---

    end  <---
end)

After All, we will run a if Statement, if the player is in the PlayersTable we will :Clone() the Gui and give it to the player like below,

Code Example, Giving Player Gui if in Table


local Gui = game.ReplicatedStorage.TopBar  

local PlayersTable = {"Roblox","BuilderMan"}

game.Players.PlayerAdded:Connect(function(Player) 
    for _,Plr in pairs(PlayersTable) do
        if Plr == Player.Name then  <---
            Gui:Clone()  <---
            Gui.Parent = Player.PlayerGui  <---
        end  <---
    end
end)

Some articles which might help:

Pairs and iPairs Tutorial - By Roblox

Conditional Structures - By Roblox

I Hope this Helps Buddy, Have a nice day!

0
Thanks! ArctemiiZ 4 — 2y
Ad

Answer this question