Hi, does anyone know how to make a command (Ranks only) to make a GUI visible/invisible? Like when you say “:GUI on” it will make the GUI visible, when you say “:GUI off” it will make the GUI invisible, that affects everyone’s screens. And only some roles can use it (Just like commands for ranks)
Utilize usage of Player.Added
and get the players rank from a group using one of the functions in the Players service, and then use remote events to affect the GUI visibility.
When a player joins your game you can attach a player.Chatted
connection to them and when a player chats the command and has the rank for that command(with a simple if statement), the server can fire a remote event to all the clients and when the clients recieve it all their guiobjects can just set their visible property to false
Use this Topic to make the Command: How To: Make Chat Commands
And use this Topic to Detect Player Group Ranks: Player:GetRankInGroup
And in the first Topic change the code a bit and add GUI.Visible
Properties.
Here is a quick example. This requires a RemoteEvent in ReplicatedStorage named UI_Visible
-- server
game.Players.PlayerAdded:Connect(function(plr)
if plr:GetRankInGroup(groupId) >= groupRole then -- replace the following with your group id and group role
plr.Chatted:Connect(function(msg)
if string.lower(msg) == ":gui off" then
game.ReplicatedStorage.UI_VISIBLE:FireAllClients(false)
end
if string.lower(msg) == ":gui on" then
game.ReplicatedStorage.UI_VISIBLE:FireAllClients(true)
end
end)
end
end)
-- client
local UI = script.Parent.Frame -- make this the path to whatever UI you want to disable
local function changeVisibility(bool)
UI.Visible = bool
end
game.ReplicatedStorage.UI_VISIBLE.OnClientEvent:Connect(changeVisibility)
local players = game:GetService("Players")
local groupId = 0 --Change to ID of group.
local groupRank = 0 --Change to required rank.
local function isInGroup(player)
local success, result = pcall(player.IsInGroup, player, groupId)
if success then
if result then
return true
else
return false
end
else
warn(result)
return nil
end
end
local function hasGroupRank(player)
local success, result = pcall(player.GetRankInGroup, player, groupId)
if success then
if result then
if result > groupRank then
return true
else
return false
end
end
else
warn(result)
return nil
end
end
local function onPlayerAdded(player)
local function onPlayerChatted(message)
if message:lower():match("^/guion$") then
if isInGroup(player) then
if hasGroupRank(player) then
for _, player in ipairs(players:GetPlayers()) do
player.PlayerGui.ScreenGui.Enabled = true
end
end
end
elseif message:lower():match("^/guioff$") then
if isInGroup(player) then
if hasGroupRank(player) then
for _, player in ipairs(players:GetPlayers()) do
player.PlayerGui.ScreenGui.Enabled = false
end
end
end
end
end
player.Chatted:Connect(onPlayerChatted)
end
players.PlayerAdded:Connect(onPlayerAdded)
The commands are /guion
and /guioff
to enable/disable every player’s gui respectively.