Brick that changes a gui's text when touched

I’m making a tutorial for my game (I’m not the best scripter at all) and I came to the conclusion that the easiest way to make text that changes is just to change it when a part is touched. I have no Idea how to do that

The script I have so far is

local brick = script.Parent
local debounce = true
local GUI = game.StarterGui.InstructionGUI.Frame

local function doSomething(otherPart)
	local Player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
	if debounce and Player then
		debounce = false
		GUI.TextLabel.Text = "Don't touch the neon. 99% of the time it will kill you."
		print("Did it work?")
		wait(2)
		debounce = true
	end
end

brick.Touched:Connect(doSomething)

Just to confirm, is this a Server Script or a Local Script?

One thing to mention is that you are trying to change the text from StarterGui, which will not work at all. You need to get the PlayerGui instead.

1 Like
local brick = script.Parent
local debounce = true

local function doSomething(otherPart)
	local Player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
	if debounce and Player then
		debounce = false
        local GUI = Player.PlayerGui.InstructionGUI.Frame
		GUI.TextLabel.Text = "Don't touch the neon. 99% of the time it will kill you."
		print("Did it work?")
		wait(2)
		debounce = true
	end
end

brick.Touched:Connect(doSomething)

Should work.

2 Likes

It’s a normal script inside of a part. Kinda new to scripting but I know it’s not a Local Script.

1 Like

Thank you so much! It worked. You are amazing.