Yes, I know its on the Roblox Dev Forum, but I couldn't seem to understand it.
If anyone could explain a bit easier, it would surely help!
Yes, I know its on the Roblox Dev Forum, but I couldn't seem to understand it.
If anyone could explain a bit easier, it would surely help!
Here's a script and explanation that minifies @GR1PP3RTV
First, let's make a table holding all the players that will see the GUI.
local whilelistedplayers = {"Player1", "Player2"}
Once you do that, we'll have to make a PlayerAdded Event
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(
function(plr)
print(plr.Name .. " has joined.")
end
)
After that, we'll have to loop through the table to detect if the player who joined is in the table.
for i, v in pairs(whilelistedplayers) do
if v == plr.Name then
local Gui = ServerStorage.Gui:Clone()
Gui.Parent = Player.PlayerGui
end
end
Okay, now let's combine everything:
local whilelistedplayers = {"Player1", "Player2"}
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(
function(plr)
print(plr.Name .. " has joined.")
for i, v in pairs(whilelistedplayers) do
if v == plr.Name then
local Gui = game.ServerStorage.Gui:Clone()
Gui.Parent = Player.PlayerGui
end
end
end
)
How the code functions:
When a player joins, the i, v in pairs loop would detect if the player who joined name is one of the whitelisted players. If yes, it would clone the GUI and put it in the PlayerGui. (make sure the Gui that will be cloned is inside ServerStorage
This also helps as well. Thanks!
Here is an explanation to understand.
Gui will be on the ServerStorage, so exploiters can't access Gui very easily.
--> Services
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
--> Variables
local Whitelist = {"Oof1", "Oof2", "Oof3"} --> You can use ID instead of names
--> Functions
local function CheckWhitelist(Player)
for Index, Value in pairs(Whitelist) do
if Player.Name == Value or Player.UserId == Value then
return true
end
end
end
--> Methods
Players.PlayerAdded:Connect(function(Player)
if CheckWhitelist(Player) then
local Gui = ServerStorage.Gui:Clone()
Gui.Parent = Player.PlayerGui
end
end)
As you can see, I created a table that contains the names of who can use the Gui, and a function called CheckWhitelist. The first argument of the function is the player object, and the function check if table values matches the player's name or ID.
So, the PlayerAdded method of Players service, will fire when a player joins the server. After the method fire, I use the CheckWhitelist function to check if the player's name or ID is in table values, if so, will clone the Gui and set the Parent to the PlayerGui of the player.
I guess this can help you.
This helps me considerably. Thanks!
Oh, I forgot. I asked this for help with my spectate button, so would you have any help on that?
I think you can do
if game.Players.LocalPlayer.Name == "YourName" then
script.Parent.Enabled = true
else
script.Parent.Enabled = false
end
and if you want to do multiple players then do this
if game.Players.LocalPlayer.Name == "YourName", "theotherguysname", "otherguysname" then
script.Parent.Enabled = true
else
script.Parent.Enabled = false
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
I can understand you, do you want a white list of who can use a specific Gui?