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

How to create a locally visible button on a GUI?

I want to create a admin/specific player GUI, so then I can control the game as an admin for testing it. I need to know how to make the GUI button only visible for those specific players, does anyone know how to do this? Or if I even can?

2 answers

What i reccomend doing is

local Admins = {  --This is the table of admins
    Player; --Change these to the admin names
    Player;
    Player;
}

local event = game:getService("ReplicatedStorage"):FindFirstChild("ToggleAdmin") --Defining Event

game.Players.PlayerAdded:Connect(function(plr) --When the player is added it saves them to storage
    plr.Chatted:Connect(function(msg) --When they chat
        for index, value in pairs(Admins) do --Loops through admins to see if its them
            if msg:lower():find(";Admin Commands") then -- If it finds ";Admin Commands" then
		if plr.Name == value then -- If the players name is equal to the admins name then
		 event:FireClient(plr) -- Fire the client to change if admin is toggled
               	 print("Working") --Tells you if its working
               	 break -- Ngl i dont know what this does but dont question it
		end
            end
        end
    end)
end)

Make sure you add an Event in replicated storage named "ToggleAdmin"

Now in a localscript in the button or frame, Do

local event = game:getService("ReplicatedStorage"):FindFirstChild("ToggleAdmin") --Define event
local frame = script.Parent --Define Button or Button
local plr = game.Players.LocalPlayer --Define player

event.OnClientEvent:Connect(function() --When admin is toggled function
	if frame.Visible == false then 
	 frame.Visible = true --If the frame isnt visible then it makes it visible
	else 
	 frame.Visible = false --If it IS visible then it disables it
	end
end)

And on the gui or frame put some admin commands with text boxes and scrolling frames I havent tested it. But it should work

Edit: Sorry for how much more complex it is now. Im trying to make sure it works!

10 comments

0

It basically just looks through to see if the person saying ";Admin Commands" Is in the admin table. And then makes the frame visible. And on the frame is where you want your admin commands

0

Please tell me if this errors. I can hopefully fix it!

0

Will it work with just a singular button so I would do something like frame = game.StarterGui.ScreenGui.AdminButton

0

You dont wanna do "game.StarterGui" Ever when it comes to changing the players screen. I'm going to edit my answer now to exactly what you need to do. But yes. that would work if you dont use "game.StarterGui

0

Sorry its so much more complex. Tell me if i made any punctuation errors

0

You dont have to use this. But if you wanna fire it with chat. Its worth a shot reading through

0

How do I add events to replicated storage (If you can't explain it just supply me with a link)

0

Right click on ReplicatedStorage, Click Insert Object. And click RemoteEvent. And rename it "ToggleAdmin"

0

I'm very new to LUA, and especially roblox OOP, but when supplied with these links I can figure out how to use these in the future

0

Links? If it worked. Please accept my answer :)

Hey there THEBOSS234222!

This is totally possible, and I have done it inside of my own games before. What you want to do is create the GUI like normal, but then insert a script (not local) into the frame (or textbox or whatever is your background part) You will want the script to look something like this:

Let's say you have a ScreenGui > Frame > Textbox. You will want to put the script inside of ScreenGui.

local player = script.Parent.Parent.Parent -- This may be different depending on what your GUI looks like. the first Parent corresponds to the ScreenGui, the second corresponds to the player's PlayerGui, and the third corresponds to the player. (If you don't know what the PlayerGui is, it is the players GUI, and it is a unique part.)

Right after that, you will want to figure out what group of players you want to see the GUI. It could be just a handful of usernames, a rank in a group, if they have a badge, etc.

If you wanted only yourself to see the GUI, your next line would be this:

if player.Name == "THEBOSS234222" then
	script.Parent.Frame.Visible = true
end

I hope this helps! If you have any questions, feel free to ask! :)

2 comments

0

That PlayerGui part was very helpful thank you.

0

Also! If you are to use this, I recommend doing "local player = game.Players.LocalPlayer" Using the "Parent" strategy can be confusing

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