Typewriter script isn't working [SOLVED]

Hi. I have a problem with my objective script.
Basically, what I want is the objective to sort of typewriter itself and disappear.
But for some reason, the text does not typewrite. It plays the sound and everything, no errors.

Typewriter script:

local function typewriter(s, label, soundFX)
	local newString
	for i = 0, s:len(), 1 do
		newString = s:sub(1, i)
		soundFX:Play()
		wait(0.02)
		if s:sub(i-1, i-1) == "," then
			wait(0.1)
		elseif s:sub(i-1, i-1) == "." then
			wait(0.4)
		elseif s:sub(i-1, i-1) == "!" then
			wait(0.5)
		elseif s:sub(i-1, i-1) == "?" then
			wait(0.3)
		end
		label.Text = newString
		wait()
	end
end

Would appreciate answers ASAP.

Iā€™m confused as to what your problem is. But, I would recommend starting i at 1.

for i = 1, s:len(), 1 do

You should first check if ā€œsā€ actually holds any value. Try printing it above your ā€œlocal newStringā€ line and if it does have a string value then check if your label is matching and if the script is on the client and not on the server.

My problem is that this script is supposed to show the text ā€˜sā€™ but the TextLabel does not change.
Also, your option didnā€™t work.

ā€˜sā€™ holds the value. It prints it properly.

finally found out what the script means

local function typewriter(s : string, label : TextLabel, soundFX : Sound)
	for i=1, string.len(s) do
		local text = string.sub(s, 1, i)
		
		label.Text = text

		if string.sub(s, i, i) ~= " " and soundFX then
			soundFX:Play()
		end

		if string.sub(s, i, i) == "," then
			task.wait(0.3)
		elseif string.sub(s, i, i) == "." then
			task.wait(0.4)
		elseif string.sub(s, i, i) == "!" then
			task.wait(0.5)
		elseif string.sub(s, i, i) == "?" then
			task.wait(0.3)
		else
			task.wait(0.05)
		end
	end
end

Indeed.

30charlimit30charlimit

Hmm. Donā€™t understand what this script is supposed to do (Iā€™m not a professional developer lol). Can you elaborate?

It is recommended to use MaxVisibleGraphemes for the typewriter effect.

OK! New problem. Iā€™ve updated the typewriter script. Still isnā€™t working lol
Typewriter script:

local function typewriter(stringValue, label, soundFX, slowness)
	for i = 1, #stringValue do
		label.Text = string.sub(stringValue, 1, i)
		wait(slowness/100)
		soundFX:Play()
	end
	wait(slowness*40)
end

My objective script doesnā€™t seem to be working. The thing is, the function carries out normally, but the frame doesnā€™t tween at ALL.
Objective script:

local function giveObjective(objective)
	objectiveFrame.Visible = true
	objectiveFrame:TweenSize(UDim2.new(0.6,0,0.15,0), "Out", "Quint", 0.1)
	typewriter(objective, objectiveLabel, game.SoundService.SND_TXT1, 5)
	objectiveFrame:TweenSize(UDim2.new(0,0,0.15,0), "Out", "Quint", 0.1)
	wait(0.1)
	objectiveFrame.Visible = false
end

does it work

local function typewriter(newString : string, label : GuiObject, soundFX : Sound, slowness : number)
	for i = 1, #newString do
		label.Text = string.sub(newString, 1, i)
		soundFX:Play()

		task.wait(slowness/100)
	end

	return
end

local function giveObjective(objectiveString : StringValue)
	objectiveFrame.Visible = true
	objectiveFrame:TweenSize(UDim2.new(0.6,0,0.15,0), "Out", "Quint", 0.1)
	typewriter(objectiveString.Value, objectiveLabel, game.SoundService.SND_TXT1, 5)
	objectiveFrame:TweenSize(UDim2.new(0,0,0.15,0), "Out", "Quint", 0.1)
	task.wait(0.1)
	objectiveFrame.Visible = false
end

Nothing tweens, the sound effect works fine for the start then keeps looping at the end.

Can i see the full script, Its works normally for me

Sorry, my code is kinda private. Iā€™m dicey about giving it away. Could you find a backdoor as these are the core components of the ObjectiveGUI?
Also itā€™s about 700 lines lol

I even put it in another localscript and it STILL isnā€™t working

kinda got lazy

Explorer:

Screenshot 2022-08-28 174942

LocalScript:

local objectiveFrame = script.Parent

local function typewriter(newString, label, soundFX, slowness)
	for i = 1, #newString do
		label.Text = string.sub(newString, 1, i)
		soundFX:Play()

		task.wait(slowness/100)
	end

	return Enum.TweenStatus.Completed
end

local function giveObjective(objectiveString)
	objectiveFrame.Visible = true
	objectiveFrame:TweenSize(UDim2.new(0.3, 0, 0.07, 0), "Out", "Quint", 0.1)
	typewriter(objectiveString, objectiveFrame, game.SoundService.SND_TXT1, 5)
	objectiveFrame:TweenSize(UDim2.new(0, 0, 0.07, 0), "Out", "Quint", 0.1)
	task.wait(0.2)
	objectiveFrame.Visible = false
end

task.wait(15) -- delay

giveObjective("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
1 Like

Works now! Thanks a lot! Iā€™m pretty bad at scripting :smiling_face_with_tear: