I have a command made, but I don’t know how I can enable the ScreenGui for the player who used the command. I’ve tried doing a few things. I tried googling, found nothing.
Code:
local admins = {"user1", "jees1", "user3", "user4", "user5"};
local Players = game:GetService("Players")
function checkAdmin(speaker)
local isAdmin = false;
for a,b in pairs (admins) do
if b == speaker.Name then
isAdmin = true;
break;
end
end
return isAdmin
end
function onChatted(msg, speaker)
if checkAdmin(speaker) then
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "!cmds" then
speaker.PlayerGui.HelpGUI.Enabled = true -- make gui visible, this does not work
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:connect(function(msg)onChatted(msg, player) end)
end)
end
Before I can help, may I ask why you must enable it on the server? Sometimes it may fail to show it to the client if you enable it on the server. A remote event won’t hurt.
I tried RemoteEvents, though it wouldn’t work. Let me provide you the code with remoteEvent:
local admins = {"user1", "jees1", "user3", "user4", "user5"};
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEventYes")
function checkAdmin(speaker)
local isAdmin = false;
for a,b in pairs (admins) do
if b == speaker.Name then
isAdmin = true;
break;
end
end
return isAdmin
end
function onChatted(msg, speaker)
if checkAdmin(speaker) then
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "!cmds" then
remoteEvent:FireClient()
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:connect(function(msg)onChatted(msg, player) end)
end)
end
LocalScript in StarterPlayerScripts:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemteEventYes")
local function onCmd()
game.Players.LocalPlayer.ScreenGui.HelpGUI.Enabled = true
end
remoteEvent.OnClientEvent:Connect(onCmd)
Just noticed a typo on the RemoteEvent in the LocalScript, but fixing that did not work.
Tried yours, didn’t work either:
local admins = {"user1", "jees1", "user3", "user4", "user5"};
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEventYes")
function checkAdmin(speaker)
local isAdmin = false;
for a,b in pairs (admins) do
if b == speaker.Name then
isAdmin = true;
break;
end
end
return isAdmin
end
function onChatted(msg, speaker)
if checkAdmin(speaker) then
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "!cmds" then
remoteEvent:FireClient(game:GetService("Players")[speaker.Name])
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:connect(function(msg)onChatted(msg, player) end)
end)
end
local admins = {"user1", "jees1", "user3", "user4", "user5"};
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEventYes")
function checkAdmin(speaker)
local isAdmin = false;
for a,b in pairs (admins) do
if b == speaker.Name then
isAdmin = true;
break;
end
end
return isAdmin
end
function onChatted(speaker, msg)
if checkAdmin(speaker) then
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "!cmds" then
remoteEvent:FireClient(speaker)
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:connect(function(msg)onChatted(msg, player) end)
end)
end
Flip speaker and msg around back to msg, speaker. Roblox also adds an invisible character to the end of chat messages, so for onChatted this should be your code:
function onChatted(msg, speaker)
if checkAdmin(speaker) then
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if string.sub(msg, 1, 4) == "!cmds" then
remoteEvent:FireClient(speaker)
end
end