So I have a spawn function which I wanna use to run a looped function while running another function at same time, this looped function although having a while loop for some reason runs only once
function Rotate(Target)
while true do
wait()
print("d")
end
end
Run.Stepped:Connect(function()
--pretend theres some code here
spawn(function()
Rotate()
end)
end)
I would recommend using repeatcodeuntil inside the spawned function since that would allow you to make it stop looping at some point, otherwise it will just continuously run forever. (or you can just break the loop from inside.)
As for it running only once, the code you provided behaves normally and loops when tried out. Could you provide the complete script so that we might be able to determine the true cause, which would be within the rest of the script.
As said above, unless a loop has a break statement in it, it will run forever, meaning any code underneath it will not be ran. If you have a loop just waiting and printing “d”, then you don’t need it. Can we see the full code so we can see what you’re trying to do please?
Saying this does not help, the issue could be anything as simple as just you using the function above or below something you should not. But we need to see the code to be able to determine that.
Your function won’t work, it’s pretty useless, also for better usage of loops and preventing loops to exhaust, you can remove the wait under your while true do and replace it with this
I tested just that part of code. It should work perfectly fine so it isn’t the spawn function.
So it is not the spawn function that doesn’t run the loop. It’s something else in your code.