Stopping while true do

How do i stop a while true do loop even after the script is destroyed. I already tried to disable it but its not working

1 Like

You use break or continue to break a while true do loop

Example:

local Number == 0

while true do
wait()

if Number >= 10 then
break -- Breaks the loop
end
Number += 1
end
4 Likes

Wow, didn’t know this before!

I don’t know how seeing as I have been scripting for like 3 years now :rofl:

Anyway, ty, and I hope the owner of the post sees this as well!

1 Like

Any code running in a script is stopped once you disable/destroy the script. You are probably destroying/disabling the script on the local side which is why it isn’t working. Try looking into remote functions/events.

Why would you do this?

You use the Server :confused:

Because hes probably destroying the script on the client, which means he will need a remote function/event to actually destroy the script on the server.

It is useless to use a RemoteEvent/RemoteFunctions for this case, RemoteEvents/RemoteFunctions are used to send data from Server -> Client and vice versa, Just use the Server, Using them is just adding an extra step.

Now I’m just confused. OP tried to break a loop by destroying the script, which should work, but doesn’t, which implies that either his code never runs or the code local, so what I’m saying is that if he is disabling/destroying the code on the client, he should use a remote event/function to destroy the code on the server instead of trying to find out why the code isn’t working. So my proposal isn’t entirely useless, I was just saying that if he was trying to do stuff on the client, it wouldn’t replicate to the server.

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