Inside the gui? or just inside the startergui
I just tested out this soruce code in studio and works. Put the localscript with next source code inside StarterGui.
local LocalPlayer = game.Players.LocalPlayer
local Whitelist = {}
if LocalPlayer.PlayerGui:WaitForChild("RadioComms").Enabled == true then
if not table.find(Whitelist, LocalPlayer.UserId) then
LocalPlayer.PlayerGui:FindFirstChild("RadioComms").Enabled = false
end
end
Hello!
My solution for enabling GUIs only for whitelisted players on client is this :
local player = game.Players.LocalPlayer
local whitelist = {
[UserId] = true;
}
if whitelist[player.UserId] == true then
--Enable gui here
end
Its better to use UserId since players can change usernames.
Enabled or disabled to begin with?
Do you have RadioComms
inside StarterGui? Try to change WaitForChild to FindFirstChild. With Enabled as Default
I fixed it because there was a space between Radio and Comms
What about adding a group onto the whitelist though?
How would I do that, I’ve never used it
Here is an example from the website I sent you, probably inside normal script.
local GroupId = 0000000 -- change to your group id
game.Players.PlayerAdded:Connect(function(newPlayer)
if newPlayer:IsInGroup(GroupId) then
print("Player is in the group")
end
end)
Hello @Yaahz,
First of all, don’t use Players.PlayerAdded
for this scenario, it is bad practice, specifically since you are using it on the client. We can do this in an easier way. Also please do sanity checks in the server, if you are doing an admin UI and you do not check who is sending the server commands, an exploiter would easily execute commands because an exploiter can manipulate anything it is client and that also includes UIs. Considering there is nothing we can do about preventing an exploiter from manipulating a UI, lets just do this client sided and do sanity checks on the server. So:
local player = Players.LocalPlayer
local whitelist = {1, 2, 3} --// user ids
local gui = --// define where the gui here
for _, id in pairs (whitelist) do
if (id == player.UserId) then
gui.Enabled = true
end
end
That is it. Also always use WaitForChild()
to access instances from the client as they may have not been loaded yet.
From what I can see, you are making a chat UI, make sure that when a player tries to send a message or view messages you check if the user is in the whitelist from the server too.
EDIT:
Since you also want the UI to open for the members of a certain group too, you can check if the player is in a group through the IsInGroup player function. You can add that below the loop. From what I can see you are just asking for code. Nothing more. This category is not a scripting request category, it is scripting support. Please try creating your own code first so we can help you.
Would look something like this :
local player = game.Players.LocalPlayer
local whitelist = {
["UserId"] = 12387123;
["GroupId"] = 1782387;
}
local enable = false
for i, v in pairs(whitelist) do
if i == "UserId" then
if player.UserId == v then
enable = true
end
elseif i == "GroupId" then
if player:IsInGroup(v) then
enable = true
end
end
end
if enable then
LocalPlayer.PlayerGui:FindFirstChild("RadioComms").Enabled = true
end
Make sure the GUI is disabled though.
Would enable be replaced by the gui.enable thing?
Do not use FindFirstChild()
on the client. Specifically on UIs. This error that Yaahz posted basically says that there is no UI named “RadioComms” inside the PlayerGui:
I realised that then I changed it
I copied that line from Solution since I didn’t know where the gui is.
Alright, don’t forget make vanity checks on the server, it is very important. Good luck developing.
Is this a LocalScript,ModuleScript,or just a script? Sorry Im new to scripting!
Besides where do you put it?
Hey,
yeah you’d use this in LocalScript and you can put it pretty much everywhere, just gotta edit it so it works.
I would recommend using a connection in a ServerScript rather than a LocalScript. If things are handled locally, it’s going to be an easy bypass. They could change their UserID, decompile your script to see how the whitelist works and crack it from there.