I’m currently writing a module script with several mechanics that get called by the main server handler script that handles them. But I have an issue where the wait function completely blocks the other scripts. (It’s also in a repeat loop, as it’s for a time based mechanic that has the time changed). I tried moving the other code above it but when it eventually reached that point, it just didn’t change anything.
Just wanting to figure out a way to make it so I can get other blocks of code within a script while a wait() function is happening, any alternatives or help would be much appreciated.
The mechanic module script:
local Mechanics = {
Errors = {
Ventilation = function()
print("Ventilation going off.")
end,
Audio = function()
print("Audio going off.")
end,
Camera = function()
print("Camera shut down.")
end,
},
timeChip = function(coolNumber)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local timeInt = ReplicatedStorage.Values:WaitForChild("Time")
timeInt.Value = coolNumber
repeat
repeat wait() until ReplicatedStorage.Values.NightBegun.Value == false
wait(5)
print("The time is currently: ".. coolNumber.. "AM")
coolNumber += 1
if coolNumber > 12 then
coolNumber = 1
end
until false
end,
}
return Mechanics
The game handler script:
-- setting up all the module scripts
local Mechanics = require(script.MechanicsLogic)
local Behaviour = require(script.BehaviourLogic)
-- main variables needed
local ReplicatedStorage = game:GetService("ReplicatedStorage")
wait()
-- making sure Time works
local timeInt = ReplicatedStorage.Values:WaitForChild("Time")
Mechanics.timeChip(12)
-- Errors (ALL IN ONE CATAGORY)
spawn(Mechanics.Errors.Ventilation)
return Mechanics
Coroutines let you run codes while certain things happen. And don’t worry because coroutines are not that difficult you can watch some tutorials about them.
You would need to use the task and coroutine libraries. Both of them are specially made for stuff like that. Note that you should use the task library instead of regular global functions. (e.g: using task.wait() instead of wait() and using task.delay() instead of delay())
And if you ask me, Why using the task library over the regular wait/spawn/delay functions? Simple, The task library is a way better and updated version of those functions. They’re also way more precise than the old ones.
You can learn more about both of the libraries here:
What is exactly not working? Also, The only difference is that the libraries (like i said) are more precise and optimized. If possible, Can you go further and explain what you exactly want to do?
My main goal is basically to have it so when this specific function is called from the ModuleScript, it can bypass the Clock timer being used for the game’s time mechanic to still run that code while the time mechanic is still going.