Dialogue typewrite effect it's not working with function (please help)

Hello,
I’m trying to make a horror game on Roblox and I discovered how to make a dialogue typewrite effect and a menu for the game, I want when you press the play button to start the dialogue. I tried this script below but it doesn’t work even though I don’t have any error.

local playbtn = game:GetService("StarterGui").ScreenGui1.BG.PlayButton

playbtn.MouseButton1Click:Connect(function()
	local function typewrite(object,text,length)
		for i = 1,#text,1 do
			object.Text = string.sub(text,1,i)
			wait(length)
		end
	end

	typewrite(script.Parent, "subscribe bro", 0.05)
end)
4 Likes

This will be the thousandth time I tell someone to DESCRIBE their issue and don’t just say “it doesn’t work”. That is not enough. We are not magicians, most of the time we cannot instantly pinpoint your issue and solve it in a heartbeat.

Also, the typewriter effect you’re trying to have can be simplified with the .MaxVisibleGraphemes property.

5 Likes

You need to divide the length with the length of the text

wait(#text / length)

(or switch if it isnt correct)

4 Likes

I’m sorry for not giving more details, I quit Roblox because I got scammed and recently I started creating some games and I noticed that many things have changed on the DevForum and yeah…

2 Likes

Also remember to use task.wait since wait is gonna get deprecated.

3 Likes

It’s not working, I wrote this:

local playbtn = game:GetService("StarterGui").ScreenGui1.BG.PlayButton

playbtn.MouseButton1Click:Connect(function()
	local function typewrite(object,text,length)
		for i = 1,#text,1 do
			object.Text = string.sub(text,1,i)
			wait(#text / length)
		end
	end

	typewrite(script.Parent, "subscribe bro", 0.05)
end)
3 Likes

Do what Veron said, use graphemes. (You don’t need to divide anything)

1 Like

And how do I write that, sorry but it’s my first time coding and I watched a YouTube tutorial from 8 months ago.

2 Likes

The issue seems to stem from this:

This is a pretty common mistake people make. StarterGui is what’s being replicated to players when they join the game. It’s not the player’s actual GUI, so editing it won’t do anything, especially from the client. You’re supposed to use LocalPlayer.PlayerGui to access it.

I’ve completely changed the script, try this:

local lp = game:GetService("Players").LocalPlayer
local playbtn = lp.PlayerGui:WaitForChild("ScreenGui1"):WaitForChild("BG"):WaitForChild("PlayButton")

local function typewrite(object, text: string, delay: number)
	object.Text = text
	local i: number = 0
	for _ in utf8.graphemes(text) do
		i += 1
		object.MaxVisibleGraphemes = i
		task.wait(delay)
	end
end

playbtn.MouseButton1Click:Connect(function()
	typewrite(playbtn, 'subscribe bro', 0.05)
end)
2 Likes

Did you even click on the link that he sent? It literally gives a perfect example of how to do it.

2 Likes

It doesn’t work, I made a Local Script and put it in TextLabel, is that the problem?

1 Like

Are there any error messages? Get into the habit of showing them here whenever one pops up

1 Like

Yes, I looked over what he sent me but I don’t understand anything because I’ve never coded on Roblox in my life and it’s the first time I try something like this. Besides, I’m not American and I don’t understand English that well.

2 Likes

There’s not a single error, I can make a Screen Recording if you would like to see. Maybe that would help!

2 Likes

If you can share the place file, that would be great, so we can experiment around with it ourselves instead of constantly going back and forth

2 Likes

You mean Team Create or should I give you the Roblox Game file?

2 Likes

gametest.rbxl (66.0 KB)

1 Like

You can’t get the PlayerGui with just a normal server script, you gotta get the player somehow. Just move this script in this LocalScript
image
or if you really want it with a server script do this

local playbtn = script.Parent.Parent.Parent.ScreenGui1.BG.PlayButton
	local function typewrite(object,text,length)
		for i = 1,#text,1 do
			object.Text = string.sub(text,1,i)
			wait(length)
		end
	end
playbtn.MouseButton1Click:Connect(function()
	typewrite(script.Parent, "subscribe bro", 0.05)
end)
1 Like

So I need to add the Script that VERON gave me into that local script? Like this?

--// Variables
local cam = workspace.CurrentCamera
local camPart = workspace["MenuCamera"]
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local PlayBTN = script.Parent.BG.PlayButton
local scary = game.Workspace.scaryplay

--// Set cam
repeat
	wait()
	cam.CameraType = Enum.CameraType.Scriptable
until
cam.CameraType == Enum.CameraType.Scriptable

--// Move cam
local maxTilt = 10
game:GetService("RunService").RenderStepped:Connect(function()
	cam.CFrame = camPart.CFrame * CFrame.Angles(
		math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
		math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
		0
	)
end)


function Play()
	cam.CameraType = Enum.CameraType.Custom
	script.Parent:Destroy()
	scary:Play()
	local lp = game:GetService("Players").LocalPlayer
	local playbtn = lp.PlayerGui:WaitForChild("ScreenGui1"):WaitForChild("BG"):WaitForChild("PlayButton")

	local function typewrite(object, text: string, delay: number)
		object.Text = text
		local i: number = 0
		for _ in utf8.graphemes(text) do
			i += 1
			object.MaxVisibleGraphemes = i
			task.wait(delay)
		end
	end

	playbtn.MouseButton1Click:Connect(function()
		typewrite(playbtn, 'subscribe bro', 0.05)
	end)
end

PlayBTN.MouseButton1Click:Connect(Play)
1 Like

When i try to do it with a Server Script I get this error: Text is not a valid member of Frame “Players.wcristy.PlayerGui.ScreenGui.Frame”

1 Like