Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I was wondering how if you chat it can change the text of the screen gui?

When i say the text the gui doesn't change text I am a bit confused as why it doesn't work but please mind me I am very new to GUI scripting. (game.StarterGui.ScreenGui.Host.Text = (string.sub(Message, 6)) the host is the text box

local admin = "playername"
local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(Player)
	if Player.Name == admin then
		Player.Chatted:connect(function(Message)
			if Message ~= nil then 
				if string.lower(string.sub(Message, 1 , 4)) == "text" then
						game.StarterGui.ScreenGui.Host.Text = (string.sub(Message, 6))
						
					end
				end
		end)
	end
end)

1 answer

✓ Accepted answer

The reason it doesn't work is because you're changing the text of the gui in StarterGui. The guis you put there are cloned into the player's PlayerGui, and that's where you should be changing it: in the PlayerGui.

However, you cannot do it from a server script. You need to use a LocalScript along with remotes to tell the client to change the text of the gui.

Example:

Server

local admin = "playername"
local Players = game:GetService("Players")
local remote = game:GetService("ReplicatedStorage"):WaitForChild("SomeRemote") --make sure to put it there :p

game.Players.PlayerAdded:Connect(function(Player)
	if Player.Name == admin then
		Player.Chatted:Connect(function(Message)
			if Message ~= nil then 
				if string.lower(string.sub(Message, 1 , 4)) == "text" then
					remote:FireAllClients(string.sub(Message, 6))
				end
			end
		end)
	end
end)

Client

local plr = game:GetService("Players").LocalPlayer
local remote = game:GetService("ReplicatedStorage"):WaitForChild("SomeRemote")

remote.OnClientEvent:Connect(function(text)
	plr.PlayerGui.ScreenGui.Host.Text = text --you can also parent the LocalScript to the gui and then use script.Parent instead
end)

5 comments

0

I still dont quite understand this can you explain more please?

0

Sure. Basically, the contents of StarterGui are cloned into every player's PlayerGui when they join. StarterGui serves as a kind of storage for templates, while the PlayerGui is where those guis end up. Each player has a PlayerGui, just like a Backpack. But, the guis copied from the StarterGui are copied locally, meaning the server won't see them. Therefor you need to use RemoteEvents to tell the

0

LocalScript to change the text of a label in the PlayerGui.

0

how come when I type this stuff in it doesn't work? Do they all need to be in a local script?

0

It also just sends not recieves

This discussion is preserved as it was. New answers, comments, and votes are closed.