How do I change a GUI text when a block is touched?

Hi! I’m learning scripting by starting with a simon says type game. My plan on how it works was to teleport a random person, then that person stands on a block which triggers a touch event making a GUI say that the players name is simon. (better ideas on how to do this are welcome)

The block is printing telling me the player touched it, but it’s not changing the GUI.
Here’s what my script looks like:

local SimonBlock = game.Workspace:FindFirstChild("SimonBlock")
local StarterGUI = game:GetService("StarterGui")
local MessageText = StarterGUI.MessageGUI.MessageText

SimonBlock.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	local Name = hum.Parent.Name
	if hum then
		print("HumanoidTouched")
		MessageText = Name.."is simon!"
	end
end)

Any help is appreciated!

2 Likes

This could be easily abused by exploiters, since they could proc Touched event by simple flying to that part, so I suggest instead making them simon in the same part of the script you choose them randomly and teleporting them.

MessageText.Text = Name.."is simon!"
You need to assign the string to the text label’s ‘Text’ property.

I somehow did not think about hackers. Good idea and I will do that, I just do not know how to connect the GUI to the script.

StarterGui is not PlayerGui, editing stuff in StarterGui doesnt edit the player’s gui while running the game

never try to edit player gui with a server script (if this is a server script) always edit player gui with local scripts because thats where the gui is stored

just change it to a local script (if it isnt already) and use player gui and everything else is fine (except MessageText, it should be MessageText.Text to set the text)

1 Like

Will the whole server see the same text when using playergui?
Or is it just the players side?

1 Like

You use PlayerGui, not StarterGui.

StarterGui is the (Starting) Gui given to players upon joining the game.

PlayerGui is the Gui given from StarterGui being rendered and used for the player.

If you are trying to apply a message to the entire server, try setting up a value, and a Changed event, so whenever you make changes to said value, it will update to all Client Gui’s. apply this change on the server to replicate to the clients.

Another way being to send a RemoteEvent to all clients, and applying said data to all Gui’s.

1 Like

if you want every client’s gui to update then have the server fire a remote to every client when the block is touched, and on the client side connect to the remote and edit the gui