Wait() no longer works for me and it breaks the code

My game was working perfectly until most of the scripts suddenly stopped working properly.
The scripts in my game would suddenly break in the middle of it, so while analysing the possible reasons I noticed that when I used wait() in a script it simply breaks after it.

Then, I replaced all the wait() with task.wait() and the code started working again, however, there were module scripts that crashed the game when I used task.wait(), so basically these scripts are no longer working as the wait() simply breaks the code.

I’ve tried disabling all of my plugins and it didn’t change anything. Seems like this glitch is only happening to me. I really need help as I need to continue developing it.

I wanted to post this is the bug report category however I’m not allowed to.

I’ll show you an example of how the game was working before and then how it is after the wait() simply started breaking most of my scripts.

AFTER (I don’t have any video of how it was working before but basically the text you are seeing on the screen had a typewriting effect with a for loop, but since the wait() breaks most of my scripts and I can’t use task.wait() inside my module without crashing I can’t fix this)

THIS IS THE MODULE SCRIPT WHERE I COULDN’T FIX BY REPLACING WAIT() WITH TASK.WAIT() AS IT CRASHED THE GAME

local TypeWriteService = {}

TypeWriteService.Type = function(object, text, length)
	for i = 1,  #text, 1 do --  the last 1 refers to the amount of characters per time
		object.Text = string.sub(text, 1, i)
		wait(0.1) -- The typewriting stops after this as the wait breaks the code
	end	
end

return TypeWriteService

By the way, I could only fix the other scripts because I could change wait() for task.wait(), even though I want to know why the wait() is making them break.

Also, yesterday I made tests where I coded:

print("Fired")
wait(5)
print("FiredAgain")

And the second part didn’t get printed. Yeah you probably understand that the wait is breaking it.

1 Like

There should be a quote mark thingy "

I mistyped it in the forum but yesterday I coded it correctly

Also are you sure you didn’t mean to do it like this?
for i = 1, #text do

Yup, but I just tested your version and the wait() still makes the code break.

could you print the text part?

Do you mean this part?
image

No, but could you try this?

local TypeWriteService = {}

TypeWriteService.Type = function(object, text, length)
	print(object, text, length)
	for i = 1,  #text do
		object.Text = string.sub(text, 1, i)
		wait(0.1)
	end	
end

return TypeWriteService

Let me know what it outputs.

Okay!

I tried your code and this was the output:

It got infinitely printed. By the way this function was called from this other script:

image

Im getting more and more confused now… :woozy_face:

Also, I tried printing inside the for loop, and it got printed 5000x.

local TypeWriteService = {}

TypeWriteService.Type = function(object, text, length)
	for i = 1,  #text do
		print("fired")
		object.Text = string.sub(text, 1, i)
		wait(0.1)
	end	
end
return TypeWriteService

image

Right, there’s nothing wrong with the typewriter script then
if your objectivestatus has a touched function changing it, make sure u use :Once instead of :Connect
or add a thing that checks if the objective has been changed and then add it to a list so it wont be changed to the same one again

Wow. I just deleted the

ObjectiveStatus.Changed:Connect(function()
	TypeWriterGuiModule.Type(ObjectiveStatus, ObjectiveValue.Value, 0.1)
end)

part of my code and now it’s working once again. Maybe this “.Changed” part could be breaking my whole game? I wonder why. The value wasn’t getting triggered to be changed infinitely. No infinite yields I found.

Btw, thats the ObjectiveStatus variable

image

image

What’s changing it infinitely though?
could you show me the script which modifies the value, name or literally anything about it?

I have no idea.
I digged into all of my scripts and none of them changed the value of the String…
None of the scripts even had this value as a variable so no possibility. Atleast that’s what I found…

The only string value that was changed in scripts was CurrentSpeechValue, however it’s working normally.

image

local SeenStatus = {}

ObjectiveStatus:GetPropertyChangedSignal("Value"):Connect(function()
	if table.find(SeenStatus,ObjectiveStatus.Value) and table.find(SeenStatus,ObjectiveStatus.Value) ~= 0 then
	else
		table.insert(SeenStatus, ObjectiveStatus.Value)
		TypeWriterGuiModule.Type(ObjectiveStatus, ObjectiveValue.Value, 0.1)
	end
end)

This is a slightly modified version of your current script and should check if it repeats the same objectivestatus or not

Oh. I just found what was wrong lol :smiling_face_with_tear: :smiling_face_with_tear: :smiling_face_with_tear:

I had two variables, one for the stringValue (ObjectiveValue) and another one for the textLabel (ObjectiveStatus).

So basically this part:

ObjectiveStatus.Changed:Connect(function()
	TypeWriterGuiModule.Type(ObjectiveStatus, ObjectiveValue.Value, 0.1)
end)

had nothing to do with the value, I was firing .Changed to a text label not a value… Lol

I just fixed the variables and now the code is working just fine! (Switched ObjectiveStatus to ObjectiveValue)

SpeechValue.Changed:Connect(function()
	TypeWriterGuiModule.Type(SpeechText, SpeechValue.Value, 0.1)
	wait(3)
	SpeechText.Text = " "
end)

ObjectiveValue.Changed:Connect(function()
	TypeWriterGuiModule.Type(ObjectiveStatus, ObjectiveValue.Value, 0.1)
end)

I hate how when developing the smallest mistakes can have such a huge impact in the whole game hahahahah

Thanks for your time trying to help btw :smile: :blue_heart:

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