Incorrect math?

  1. What do you want to achieve? Keep it simple and clear!
    I want the speed of how fast the text prints to match my totalDuration time

  2. What is the issue? Include screenshots / videos if possible!
    what it does now is take more than a second and if i put the number lower, then it will last that time but the text will stop printing and just cut to being fully displayed even though it didnt ifinish typing it

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    only chatGPT

-- local dbTime = 1

local function TypeWrite(obj, text)
	local totalDuration = dbTime
	local totalWaitTime = 0
	for i = 1, #text, 1 do
		obj.Text = string.sub(text, 1, i)
		local durationPerCharacter = (totalDuration - totalWaitTime) / (#text - i + 1)
		wait(durationPerCharacter)
		totalWaitTime = totalWaitTime + durationPerCharacter
		print(totalWaitTime)
	end
end

Hi, if you know the length of text, and what each letter should have of duration, then it is quite simple. :slight_smile:

local letter_duration = 0.1
local text = "Hello world how do you do!"
local text_length = string.len(text)

local total_duration = text_length * letter_duration

When that is said, to limit the amount of letters shown, you can use MaxVisibleGraphemes instead.

local letter_duration = 0.1
local text = "Hello world how do you do!"
local text_length = string.len(text)

local total_duration = text_length * letter_duration -- total time not needed or?
obj.MaxVisibleGraphemes = 0
obj.Text = text
for i = 1, text_length, 1 do
	obj.MaxVisibleGraphemes += 1
	task.wait(letter_duration)
end
1 Like

Ive worked that into this, I dont want to limitt the amount of letters shown, but it doesnt do anything now

local function TypeWrite(obj, text)
	local totalDuration = dbTime
	local letter_duration = 0.1
	local text_length = string.len(text)
	local total_duration = text_length * letter_duration
	
	for i = 1, text_length, 1 do
		obj.Text = string.sub(text, 1, i)
		task.wait(letter_duration)
	end
end

Got it working with this. Thanks!

local dbTime = 1

local function TypeWrite(obj, text)
	local totalDuration = dbTime
	local textLength = string.len(text)
	local letterDuration = totalDuration / textLength

	for i = 1, textLength, 1 do
		obj.Text = string.sub(text, 1, i)
		task.wait(letterDuration)
	end
end

Please use the MaxVisibleGraphemes property to typewrite!

Side note: Mark posts as the solution if you believe a post has solved your issue. Try not to mark your own post if somebody else clearly helped you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.