Localscript change gui text on part touch

I am trying to make it so that once my character touches a part in game, a GUI text in StarterGui is changed to something else (Whilst using the animation).

I have an idea that I am to use RemoteEvents, however, I have no idea how they work and developer hub didn’t help.

Here is the code I have in my LocalScript within a part:

local Dialouge = game.StarterGui.Quest.Frame.Missionguide
local Text = game.StarterGui.Quest.Frame.Missionguide
local Players = game:GetService("Players")
local TouchPart = workspace["GUIpartA"]
local db = false

local function typing(Dialouge, text)
	for i = 1,#text do
		Dialouge.Text = string.sub(text,1,i)
		wait(0.055)
	end
end


TouchPart.Touched:Connect(function(touched)
	if not db then
		db = true
	print("Touched")
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
		local Player = Players:GetPlayerFromCharacter(touched.Parent)
		if Player then
				typing(Dialouge, "Make your way across the lava bed.", 3, true, 0.05)
				wait(120)
				db = false
			end
		end
	end
end)

If anything doesn’t make sense, please let me know,
Thank you!

Hi, localscripts do not work in workspace, try moving it to startergui, or starterplayerscripts/startercharacterscripts. After that replace the location of the part and it should work correctly.

4 Likes

I will recommend you to use a debounce there because your code will run each time when the character touches that part

1 Like

I got it to work.

I just added a debounce, changed the script location to StarterGui (which it still didn’t work but it did help.)

And then I just changed the script by using part.touched instead.

local Dialouge = script.Parent.Quest.Frame.Missionguide
local Text = script.Parent.Quest.Frame.Missionguide
local Players = game:GetService("Players")
local TouchPart = workspace["GUIpartA"]
local db = false

local function typing(Dialouge, text)
	for i = 1,#text do
		Dialouge.Text = string.sub(text,1,i)
		wait(0.055)
	end
end

TouchPart.Touched:Connect(function(hitConnect)
	if not db then
		db = true
		print("Touched")
		if hitConnect.Parent:FindFirstChild("Humanoid") then
				typing(Dialouge, "Make your way across the lava bed.", 3, true, 0.05)
				wait(120)
				db = false
		end
	end
	end)