Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I fix this gui to where it only shows up for certain players?

I have a gui in StarterGui, ScreenGui is named MyGui, I am attempting to whitelist it to where only certain players (Only me right now) can view the gui, but when I play the game on a different account/guest, the gui is still there. I have this script in the ScreenGui, but not a frame. I don't know if it's supposed to go there. (I'm kind've new to scripting)

Edit: The error is line 13 with gui: but I don't know what to change it to. (I deleted the code I was using before) and I also tested this as an alt. It still showed.

Players.Player1.PlayerGui.ScreenGui.LocalScript:13: attempt to index global 'gui' (a nil value)

local Whitelisted = {'DontBlinkDrWho'}
local player = game.Players.LocalPlayer
local Allowed = false

for _, PlayerName in ipairs(Whitelisted) do
    if PlayerName == player.Name then 
        local gui = script.Parent
        gui.Parent = player:WaitForChild('PlayerGui') -- No point to possibly find nil then retry w/ WaitForChild
        Allowed = true
    end
end

if not Allowed then gui:Destroy() end 

1 comment

0

I edited stuff in the main post. (It isn't working still)

1 answer

Hello! When you post code on this website, everyone appreciates it when you press the Code Block button, it's that blue circle with 'Lua' in it. Paste the code inside of the ~~~~ lines that appear so it will be correctly formatted for us to easily view your script!

Be sure you are using a LocalScript inside of this GUI, all GUI's should function with a LocalScript!

Now that we are sure we have a LocalScript, you appear to be doing this in some-what more complex way then needed, being that you're using a Dictionary when you could use an Array (Forms of a table). So first your table would look like this: local Whitelisted = { 'DontBlinkDrWho' }. Now, because this is inside of StarterGui, you must remove this GUI if they are not in your Whitelist otherwise they will still automatically receive this GUI. To do this, if they are not in Whitelisted, we use the :Destroy() method to remove this GUI.

  • Bellow is the coding of the finished LocalScript Keep in mind, I made it so LocalScript's parent is the ScreenGui and ScreenGui is inside of StarterGui!
local Whitelisted = {'DontBlinkDrWho'}
local player = game.Players.LocalPlayer
local Allowed = false

for _, PlayerName in ipairs(Whitelisted) do
	if PlayerName == player.Name then 
		local gui = script.Parent
		gui.Parent = player:WaitForChild('PlayerGui') -- No point to possibly find nil then retry w/ WaitForChild
		Allowed = true
	end
end

if not Allowed then gui:Destroy() end 

If this helped, accept the answer! Any question/problems? Comment them bellow

This discussion is preserved as it was. New answers, comments, and votes are closed.