How to slow down scripts around a time_scale attribute?
Alright, after diving into the DevForum for a good hour, I found a simple answer.
I’ll do step by step on how to do this.
-- type this in the Studio command console
workspace:SetAttribute("TIME_SCALE", 1)
Then, Inside your chosen loop, proceed to install this:
local SERVICES = game
local WORKSPACE = SERVICES:GetService("Workspace")
local TIME_SCALE, A = WORKSPACE:GetAttribute("TIME_SCALE"), 0
local TIME_ = 5
local START_T = tick() -- debug
while A < 1 do
A = A + (wait() / (TIME_ / TIME_SCALE))
end
print(tick() - START_T) -- shows how much time has passed
Now, because the TIME_
property is dependant on the TIME_SCALE
property, if you were to change TIME_SCALE
to .5
, it would lengthen the loop to 10 seconds instead of 5, and so on.
Using this logic, myself and possibly somebody else could use this technique and implement it into their code for slowdowns.
I will not private this post as compared to last one so others can benefit.
(And for those of you who need it, this is how I coded my AI to align with the TIME_SCALE
. This code is a WIP.)
------------------------------------------------------------------------------
function AI_SCRIPT.START(PLAYER: Player)
local T_CHARACTER = PLAYER.Character
------------------------------------------------------------------------------
local T_HUMANOID = T_CHARACTER:FindFirstChild("Humanoid")
local T_HUMANOID_ROOT_PART = T_CHARACTER:FindFirstChild("HumanoidRootPart")
local T_TORSO = T_CHARACTER:FindFirstChild("Torso")
local T_HEAD = T_CHARACTER:FindFirstChild("Head")
local T_RIGHT_ARM = T_CHARACTER:FindFirstChild("Right Arm")
local T_RIGHT_LEG = T_CHARACTER:FindFirstChild("Right Leg")
local T_LEFT_ARM = T_CHARACTER:FindFirstChild("Left Arm")
local T_LEFT_LEG = T_CHARACTER:FindFirstChild("Left Leg")
------------------------------------------------------------------------------
local function HANDLER_()
------------------------------------------------------------------------------
local TIME_SCALE, ALPHA = WORKSPACE:GetAttribute("TIME_SCALE"), 0
local TIME = math.random(5, 20)
------------------------------------------------------------------------------
local START_T = tick()
if DEBUG_MODE then
print("BASE ACTION TIME -", TIME)
end
------------------------------------------------------------------------------
while ALPHA < 1 do
TIME_SCALE = WORKSPACE:GetAttribute("TIME_SCALE")
FOLLOW_(PLAYER, T_HUMANOID_ROOT_PART, TIME_SCALE)
------------------------------------------------------------------------------
ALPHA = ALPHA + (wait() / (TIME / TIME_SCALE))
end
------------------------------------------------------------------------------
if DEBUG_MODE then
print("FINISHED AT -", (tick() - START_T), "SECONDS")
end
------------------------------------------------------------------------------
ABILITY_()
HANDLER_()
end
HANDLER_()
------------------------------------------------------------------------------
end
function FOLLOW_(PLAYER, T_HUMANOID_ROOT_PART, TIME_SCALE)
HUMANOID.WalkToPoint = T_HUMANOID_ROOT_PART.Position
HUMANOID.WalkSpeed = (16 * TIME_SCALE)
end
function ABILITY_()
HUMANOID.WalkToPoint = HUMANOID_ROOT_PART.Position
warn("This is a test, move will end at a base of 5 seconds, however, can be affected by timescale.")
local TIME_SCALE, ALPHA = WORKSPACE:GetAttribute("TIME_SCALE"), 0
local TIME = 5
local START_T = tick()
while ALPHA < 1 do
TIME_SCALE = WORKSPACE:GetAttribute("TIME_SCALE")
------------------------------------------------------------------------------
ALPHA = ALPHA + (wait() / (TIME / TIME_SCALE))
end
print("Ability ended at -", (tick() - START_T), "seconds.")
end
``
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.