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

How to create a locally visible button on a GUI?

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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!

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 Galaxybombboy 134 — 3y
0
Please tell me if this errors. I can hopefully fix it! Galaxybombboy 134 — 3y
0
Will it work with just a singular button so I would do something like frame = game.StarterGui.ScreenGui.AdminButton THEBOSS234222 0 — 3y
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 Galaxybombboy 134 — 3y
View all comments (6 more)
0
Sorry its so much more complex. Tell me if i made any punctuation errors Galaxybombboy 134 — 3y
0
You dont have to use this. But if you wanna fire it with chat. Its worth a shot reading through Galaxybombboy 134 — 3y
0
How do I add events to replicated storage (If you can't explain it just supply me with a link) THEBOSS234222 0 — 3y
0
Right click on ReplicatedStorage, Click Insert Object. And click RemoteEvent. And rename it "ToggleAdmin" Galaxybombboy 134 — 3y
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 THEBOSS234222 0 — 3y
0
Links? If it worked. Please accept my answer :) Galaxybombboy 134 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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! :)

0
That PlayerGui part was very helpful thank you. THEBOSS234222 0 — 3y
0
Also! If you are to use this, I recommend doing "local player = game.Players.LocalPlayer" Using the "Parent" strategy can be confusing Galaxybombboy 134 — 3y

Answer this question