Making a while loop without stopping the rest of my script

I think the name of the topic explains the problem.
I have a while loop in my script that stops the rest of the script when activated and that is bad pls help thanks

3 Likes

Could you show us what the code is as well the errors?

i know my english is bad but isnt that’s easy to understand, when you run a while loop in a script the rest of the script and all the while loops in it stop working until that first while loop that is currently running will stop doing it thing, and i want so the script run several while loops at the time

I honestly don’t think that’s a good practice. What are you trying to do with the while loops?

ok that looks smth like this

Event.Event:Connect(function(Text)
while #Text<50 do
Text = Text … “help me”
)

Event.Event:Connect(function(OtherText)
while #OtherText<50 do
OtherText = OtherText … “ghghghg12312”
)

and these events happening almost in the same time so the first while loop just stops running after the second starts doing smth whatever it does in this script that i just wrote

Could you show me the full code? I really don’t understand what your trying to do.

whatever i think someone else will get it, not like im asking how to make the whole like dialogues system all i need is a simple command that will make sure that the script wont stop after i run a loop. thanks for trying to help

Why are you running 2 of the same events?

Are you doing this for a textlabel?

you should do

repeat
if #OtherText < 50 then
OtherText.Text = OtherText.. “ghghghg12312”
end
until #OtherText > 50

i have 2 separate textlabels with while loops which do that cool animation for a text. I dont rily understand how’s that info is helpful though

ok ill try repeat loop i dont know how will that help tho

it keeps repeating until the text is greater than 50
You could also try repeating a function.

isnt it the same thing but written differently? and btw i tried it in my script and it became only worse are you sure you good at scripting i mean u a builder. Ok repeating a function, can u show me what you mean in the script cuz
repeat
somefunc()
until smth

is basicly the same

1 Like

did u just name ur self im a loser lol. or was it before

It been like that, I have a question are you using a remote event?

yeah i am (why was orevios post bloked idk trying to get to three zero character)

I’m pretty sure you dont use .Event
.OnServerEvent or OnClientEvent if your doing it client sided.

dude i am not stupid do o event see the question? btw this is your description: I am a talented builder and UI maker. I also do scripting, but I am not that advanced. And that’s all true idk why you are even trying to help me with script lol

You can approach this in a few ways but you need to create another thread, you should read up on threading code.

You want to either use a coroutine or task.spawn, both of which generally serve the same purpose:
https://developer.roblox.com/en-us/api-reference/lua-docs/coroutine
https://developer.roblox.com/en-us/api-reference/lua-docs/task

Usually I use coroutine.wrap, but coroutine.create and task.spawn both do what you’re looking for.

coroutine.wrap(function()
    while true do
        print('loop 1')
        task.wait(1)
    end
end)()
coroutine.wrap(function()
    while true do
        print('loop 2')
        task.wait(5)
    end
end)()

Using coroutines will cause both loops to run simultaneously.

8 Likes

ok i’ll read this one minnnnnnute

1 Like

.Event is the RBXScriptSignal object for BindableEvent instances, it is fired when the instance method Fire() is called on the same BindableEvent instance.

1 Like