How can I enable a screenGUI for a player from the server?

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

Any help is appreciated, thanks!

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.

You can simply do player.PlayerGui.whateveryouwanthere.Enabled = true.

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)

image

FireClient() requires player as a parameter.

Do you mean speaker in this case?

In this case the parameter for FireClient() could be. game:GetService(“Players”)[speaker.Name]

I’m pretty sure game:GetService(“Players”)[speaker.Name] is the same thing as just speaker.

Yep my mistake. speaker and the code I wrote are the same.

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

And, yes the speaker didn’t work either.

Also the parameters are flipped around I think. It should be speaker, msg.

Doesn’t seem to fix it.

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

Doesn’t seem to fix it. Though, no worries as I’ve decided to use GUI’s instead of the help command.

1 Like