No continuous loops like while wait() do, renderstepped, heartbeat, etc work.
I’ve tried everything, I didn’t find such thing in the threads.
So the script is inside a module script, it’s childed. So it might be a lua problem.
Edit: Found the problem I think.
Edit2: I’m using a server side converter.
Edit3: Apparently I wasn’t clear, so, the script when it was intended, a localscript, relied heavily on while wait() do. But the thing is that they work on the script, just that some variables are skipped or entire functions in the entire script. I think it’s an issue with local, but i’ll go further into it.
Edit4: The problem is entirely different, as it seems, it just refuses to manipulate a player’s character, any player’s character.
This is not a lot of information to go off of.
Here are some things to know:
A module scipt can use loops just fine. There is nothing preventing them from doing so.
You can’t just parent scripts or local script to module scripts and expect results: they won’t run, and you can call them. Keep your module code TYPED inside the module script.
Module scripts are server-sided for server scripts, and client sided for local scripts. It depends on what script is using it.
it’s not an issue, are you sure you require the module,
and return something from the module too?
if you need to run functions you could just return a table containing them .
functions = {}
functions.functionA = function () print("function A executed") end
functions.functionB = function () print("function B executed") end
return functions
-- in another script
local module = require(game.ReplicatedStorage.ModuleScript)
module.functionA() --> "function A executed" in output
module.functionB() --> function B executed
You also can’t put any code after you return a value from a module.
ModuleScripts are secondary scripts that are used for creating functions in them to return certain values to other scripts. So I don’t think a loop will work outside a function in a modulescript.
Having a module script is basically just for organization, nothing else(well, almost).
For example:
function foo()
while true do
wait()
end
end
foo()
is the same as
--// Module Script
module = {}
function module.foo()
while true do
wait()
end
end
return module
--// Server Script
local Module = require() -- the module
Module.foo()
Since Lua is single threaded, it will not run other lines until the previous line has finished executing. So the script above would more or less look this this:
--// This
function foo()
while true do
wait()
end
end
foo()
--// Is the same as this
while true do
wait()
end
This is why it doesn’t work, because the loops won’t give the script enough time to get to all the functions. To counter this, use coroutines:
function foo()
while true do
wait()
end
end
coroutine.wrap(function()
foo() -- This will run
end)()
foo() -- This will also run
foo() -- This will not run
It’s already called and all, everything works, just that the loop won’t output stuff directly. The module is just to handle parenting and the script does all the work. So it’s parented into the player’s playergui, and turns out stuff tends to mess up on playergui. For example, Scripts alone won’t run. I think it’s a bug or something.
I found out what is really wrong, so anything that is parented related to the player will literally ignore stuff like anchored on the player. I think it’s a converter problem.
I found the problem, but the fix is very hard to apply, so I’m using literally an API to give a script a localscript-like enviroment for script builders. So the problem is that it won’t register the player’s character children in studio. Now I don’t have a real way to test the functions since they’re failsafes and they’re hard to trigger.
Sounds good, let me test it out, the loop works without the coroutine, because it’s already at the end of the script, the thing is that it won’t even unanchor stuff, so I will test this and get back to you.
The script runs in 4 different loops, in which in a localscript worked perfectly, the 1st too fired when a tool equipped or unequipped, and all the loops run, just that they sit there and do nothing, just print.
May you show us the scripts so we can help you? Specifically the modules and where the loops are located. Make sure to highlight where the problems are with comments:
Well, the module loads the script onto the player, so the loops are handled by the script.
Basically the loop is part of a server side script, that it’s used for script builders to, have fun.
The thing is, the loop handles some teleportation and especially prevents skids from freezing you or messing with your joints. At wich point, I’ve set prints to the loops, and they run, just that they won’t specifically do what they’re told so.