The code below checks if a players UserId is the same as the one in the table and if they type !Admin in the chat its meant to make a UI visible or invisible depending on its state.
This works in studio but doesn't in a regular server? How would I make it work in a regular server?
--- Turning Admin UI on and Off
local admins = { 21063444; } local function IsAdmin(Player) for _,Admin in pairs(admins) do if type(Admin) == "number" and Admin == Player.UserId then return true end end end game.Players.PlayerAdded:Connect(function(Player) Player.Chatted:Connect(function(message, recipient) if not recipient and IsAdmin(Player) then if message == "!Admin" then if Player.PlayerGui.Console.Main.Visible == true then Player.PlayerGui.Console.Main.Visible = false elseif Player.PlayerGui.Console.Main.Visible == false then Player.PlayerGui.Console.Main.Visible = true end end end end) end)
The problem with this script is that the script is working on the server and attempting to make changes to the client (which includes UI).
This cannot happen without the help of a RemoteEvent.
Here is what your script should look like:
local admins = { 21063444; -1; --For testing inside of Studio } local function IsAdmin(Player) for _,Admin in pairs(admins) do if type(Admin) == "number" and Admin == Player.UserId then return true end end end game.Players.PlayerAdded:Connect(function(Player) Player.Chatted:Connect(function(message, recipient) if not recipient and IsAdmin(Player) then if message == "!Admin" then game.ReplicatedStorage.Toggle:FireClient(Player) end end end) end)
Find ReplicatedStorage and place a RemoteEvent in there, and name it "Toggle".
Next, create a LocalScript inside of Main. This is what it should look like:
game.ReplicatedStorage.Toggle.OnClientEvent:Connect(function() if script.Parent.Visible == true then script.Parent.Visible = false elseif script.Parent.Visible == false then script.Parent.Visible = true end end)
The reasoning behind this is that when then RemoteEvent is fired (line 20 of the first script), a LocalScript on the client can receive the signal and create a reaction (basically the whole LocalScript) since LocalScripts can make changes on the client and regular scripts cannot.