Need Help With .Touched Script

I was following a tutorial on how to make text appear when a part is touched and need some help. I am trying to make a typewriter effect also happen when the function is called.

Script in the part text will appear in:

local debounce = false


script.Parent.Touched:Connect(function (hit)
	if not debounce then
		debounce = true
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
			game.ReplicatedStorage.ShowGui:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
		end
		wait(10)
		debounce = false
	end
end)

The Setup In Studio:


Type-writer effect script:

local textLabel = script.Parent:WaitForChild("TextLabel")

local function typeWrite(object,text)
	for i = 1,#text,1 do
		object.TextLabel = string.sub(text,1,i)
		wait(0.2)
	end
end

script in GUI:

game.ReplicatedStorage.ShowGui.OnClientEvent:Connect(function()

script.Parent.TextLabel.Visible = not script.Parent.TextLabel.Visible

end)

Please help me solve this problem, Thanks!

1 Like

In the typewrite effect script, check the object.TextLabel to object.Text because Textlabel is not a vaild member of ScreenGui.TextLabel. Also try to combine the 2 localscripts and it will look like this.

local textLabel = script.Parent:WaitForChild("TextLabel")

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

game.ReplicatedStorage.ShowGui.OnClientEvent:Connect(function()
	script.Parent.TextLabel.Visible = not script.Parent.TextLabel.Visible
	typeWrite(textLabel, " ") -- Anything
	wait(5)
end)
1 Like

yo did i mess something up it isnt working

local textLabel = script.Parent:WaitForChild("TextLabel")

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

game.ReplicatedStorage.ShowGui.OnClientEvent:Connect(function()
	script.Parent.TextLabel.Visible = not script.Parent.TextLabel.Visible
	typeWrite(textLabel, "I will not go in the lake.") -- Anything
	wait(5)
end)
1 Like

What do you mean with ‘it isn’t working’? What is happening, exactly? Send video of the what happens, please.

3 Likes

Yeah, what exactly isn’t working?

1 Like

It isn’t displaying the textLabel

1 Like

You want someone to touch a block and a text label appears?

1 Like

@AidanPlaysYT_Real
Yeh, the code should work. Are you sure you textlabel’s visible property isn’t initially false.
script.Parent.TextLabel.Visible = not script.Parent.TextLabel.Visible

1 Like

Yeah it might have been on false. Let me see if that fixes it.

Edit: It doesn’t The TextLabel should appear when you walk up, not everywhere.