How could I improve my Intro Script?

You’re a really smart guy. I wouldn’t doubt if you told me you’ve learned multiple other programming languages. You’re fast, efficient and you explain very well, crazy :+1:

3 Likes

Do note that:
task.desynchronize() and task.synchronize() can only run under scripts that are a descendant of an Actor. Else, the script would error.

1 Like

Thread is when you can pass through the script or do not stop other scripts even if there is a while loop for example, am I correct?

1 Like

That is really good, thank you!

1 Like

Why is the sound script not working?

for _,v in pairs(script.Parent:GetDescendants()) do
	if v.ClassName == "TextButton" then
		v:GetPropertyChangedSignal("MaxVisibleGraphemes"):Connect(function()
			script.Text:Play()
		end)
	end
end
1 Like

Imagine an actual thread :thread:. If we were to split it into two using task.desynchronize or coroutine.create, we will have… two threads! Okay, that was stupid but you get it.

These threads have their own code and work alongside each other.
If we had one thread running two loops, the first one would run but not the second one. However, if we had one loop on both threads, both loops would run.

while true do
--do something
end --will run

while true do
--do something else
end --will not run

--____________________--
------First Thread------
while true do
--do something
end --will run

-----Second Thread------
while true do
--do something else
end --will also run
4 Likes

I got it!! Also that was a good example not gonna lie XD. So threads makes you able to run multiple tasks at the same time?

2 Likes

That is correct!

Both coroutines and the task library work with threads well.

3 Likes

Thank you guys! You are helping me a lot! I am getting even more knowledges for yall :>. I will learn that, I will learn everything from Lua! Thank you for giving me the start.

3 Likes

Glad we could help you! Remember that you can still have help from others, you don’t need to learn everything yourself.

2 Likes

Thank you :> I will count with you and @Youf_Dev in case I need. If you want, of course XD

Talking about that, how long have you been working with Lua?

2 Likes

:IsA() is more reliable than checking the instance’s ClassName

for _, v in pairs(script.Parent:GetDescendants()) do
	if v:IsA("TextButton") then
		v:GetPropertyChangedSignal("Text"):Connect(function()
			repeat task.wait() until not script.Text.IsPlaying
            script.Text:Play()
		end)
	end
end

Might not work, but give it a go!

1 Like

I’ve been using Luau for almost a year now.

1 Like

Oh boy I forgot to add that! That’s true though and I knew it lol

1 Like

Wait! I may know why, the GUI always replicate on the PlayerGui, the local script is not inside the GUI and yes on the StarterGui! It is getting the not replicated GUI!

1 Like

That should be correct then. Well done for your problem solved.

Wait I am dumb… I found the problem. It works!

2 Likes

I might going to do another Menu, althought, this post just gave me even more knowledges about the matter, thank you everyone! The post is closed!

3 Likes

Why did you use coroutine this time? Since tween runs with no need of any more threads? Is that because of the for loop, though?

It’s because of the task.wait()'s in the tween function. If I didn’t use coroutine, the functions would run one by one. In other words, textbox1 will call the function and once it’s done then textbox2 will call the function and so on. The problem is we want to ignore the task.wait()'s so they all run at the same time. Using coroutine.wrap()() is perfect for that.

Here is an example of calling a function multiple times with and without using coroutine!

Without using coroutine:

SCRIPT:

function waitFunction()
	print("Hello World!")
	wait(3)
end

waitFunction()
waitFunction()
waitFunction()

OUTPUT:

Hello World!
-- wait 3 seconds
Hello World!
-- wait 3 seconds
Hello World!
-- wait 3 seconds
Using coroutine:

SCRIPT:

function waitFunction()
	print("Hello World!")
	wait(3)
end

coroutine.wrap(waitFunction)()
coroutine.wrap(waitFunction)()
coroutine.wrap(waitFunction)()

OUTPUT:

Hello World!
Hello World!
Hello World!

As you could tell, when using coroutine, the waits are ignored and it prints “Hello World!” at the same time. Hope I helped!