Hey, I was trying to make a custom time system to be able to freeze, speed up, slow down, etc. So it could be used to base any attacks or moves within my game to be able to freeze time and stuff like that. but I am unclear on how I would go about making this available through any script in the game. currently its a module script that creates a separate time system in every script.
I have looked through some of the devforum and creator hub but nothing seems to be about what I am trying to do. I am wondering what the best way to do this would be. I have tried using value objects to store the first four variables but this didn’t work and also did feel like it was the right way of going about this.
Here is my current code:
local start = 0
local freeze_time = 0
local frozen = false
local freeze_start = 0
local TimeModule = {}
-- Sets up the time
TimeModule.Start = function(timeFolder)
start = time()
freeze_time = 0
end
-- Freezes the time at the current time
TimeModule.Freeze = function()
if frozen == false then
freeze_start = time()-start - freeze_time
frozen = true
end
end
-- Unreezes the time at the current time
TimeModule.Unfreeze = function()
if frozen == true then
frozen = false
freeze_time = (time()-start) - freeze_start
end
end
--Gets the current simulation time
TimeModule.GetTime = function()
if frozen == true then
freeze_time = (time()-start) - freeze_start
end
return time()-start - freeze_time
end
return TimeModule
Any help would be very appreciated, also if I’m doing this in a stupid way please tell me.