How do I make a click detector display text?

Me and my friend are making a game and we have a thing so if you enter a room it says “welcome to [room name]” but I want to have that for a click detector door that says “The door is locked”

Heres a video of what the text thing looks like

This is what the text looks like in Workspace
image

The Script script:

local Trigger = script.Parent:WaitForChild("Trigger")
Trigger.Transparency = 1
local Configuration = script.Parent:WaitForChild("Configuration")

local PlayerTable = {}

Trigger.Touched:Connect(function(Part)
	local Player = game:GetService("Players"):GetPlayerFromCharacter(Part.Parent)
	if Player and PlayerTable[Player] == nil then
		PlayerTable[Player] = true
		local GUI = script.DialogueEvent:Clone()
		Configuration:Clone().Parent = GUI
		GUI.Parent = Player.PlayerGui
	end
end)

The Main script:

function SubtitleText(speech, TextLabel)
for i = 1, #speech do
TextLabel.Text = string.sub(speech, 1, i)
wait(0.04)
end
end
local Configuration = script.Parent:WaitForChild("Configuration")
Configuration.Text.Value = string.gsub(Configuration.Text.Value, "player", game:GetService("Players").LocalPlayer.Name)
Configuration.Text.Value = string.gsub(Configuration.Text.Value, "Player", game:GetService("Players").LocalPlayer.Name)
Configuration.Text.Value = string.gsub(Configuration.Text.Value, "PLAYER", game:GetService("Players").LocalPlayer.Name)
if Configuration.Book2Text.Value == false then
script.Parent.CutsceneText.TextColor3 = Configuration.TextColor.Value
script.Parent.CutsceneText.Visible = true
SubtitleText(Configuration.Text.Value, script.Parent.CutsceneText)
wait(2)
script.Parent.CutsceneText.Visible = false
script.RemoteEvent:FireServer()
elseif Configuration.Book2Text.Value == true then
script.Parent.NewCutsceneFrame.CharacterName.TextColor3 = Configuration.TextColor.Value
script.Parent.NewCutsceneFrame.CutsceneText.TextColor3 = Configuration.TextColor.Value
script.Parent.NewCutsceneFrame.CharacterName.Text = Configuration.Speaker.Value
if string.lower(Configuration.Speaker.Value):find("player") then
script.Parent.NewCutsceneFrame.CharacterName.Text = game:GetService("Players").LocalPlayer.Name
end
script.Parent.NewCutsceneFrame.Visible = true
SubtitleText(Configuration.Text.Value, script.Parent.NewCutsceneFrame.CutsceneText)
wait(2)
script.Parent.NewCutsceneFrame.Visible = false
script.RemoteEvent:FireServer()
end

I also think it might be a free model or tutorial because he’s not that good at scripting

3 Likes

First you need to detect when ClickDetector was clicked ClickDetector.MouseClick:Connect(function()

Then for the text you can watch the YouTube videos by Alvinblox, here: Text Typewriter Effect in GUIs - Roblox Scripting Tutorial - YouTube

1 Like

Alright I tried it with the click detector script:

local ClickDetector = workspace.Door2.Door3.ClickDetector
local textLabel = script.Parent:WaitForChild("Main"):WaitForChild("Text")

local function typewrite(object,text)
	for i = 1,#text,1 do
		object.Text = string.sub(text,1,i)
		wait(0.05)
	end
end

ClickDetector.MouseClick:Connect(function()
typewrite(textLabel,"Door is locked")
	
end)

and It is still not working

Try this:

local ClickDetector = workspace.Door2.Door3.ClickDetector

local function typewrite(object,text)
	for i = 1,#text,1 do
		object.Text = string.sub(text,1,i)
		wait(0.05)
	end
end

ClickDetector.MouseClick:Connect(function(plr)
	local gui = plr.PlayerGui
	local mainGui = gui:WaitForChild("Main") -- Main Gui
	local text = mainGui:WaitForChild("Text") -- Text
	typewrite(text, "Door is locked")
end)

Insert a Script into a Door and paste a code above.

just copy the code from the other typewrite

image
like that? because its still not working

There’s any error on your output? Well the Script can be put anywhere actually.

The lack of Variables makes it very hard to understand what everything does/makes it hard for us to read what is exactly the problem in this script.

What i would suggest it looping through the doors, and if a door has been clicked, you play the text that needs to be shown.

There was no error also sorry for the late reply, i was busy

Can you send a photo of your Main GUI?

First off, this is incredibly messy and should be cleaned up. Whenever you deal with code, you want to make sure it’s easy to read for others and yourself.

Second, I bet the reason your code is not working is specifically because of this line. Your code is trying to grab an instance that is most likely not loaded in the game yet. This causes stuff to break and not work since it can’t be defined correctly. Everything else seems to look fine.