I might have created slow motion possible on roblox

So, this is my script:

function module:SlowMotion(enabled: boolean, timeScale: number)
    timeScale = timeScale or 0.3
    local Formula = (enabled and timeScale or (1 / timeScale))
    workspace.Gravity = workspace.Gravity * Formula

    for _, v in workspace:GetDescendants() do
        if v:IsA("BasePart") then
            v.AssemblyLinearVelocity = v.AssemblyLinearVelocity * Formula
            v.AssemblyAngularVelocity = v.AssemblyAngularVelocity * Formula
        elseif v:IsA("humanoid") then
            v.WalkSpeed = v.WalkSpeed * Formula
            v.JumpPower = v.JumpPower * Formula
        elseif v:IsA("Linearvelocity") then
            v.MaxForce = v.MaxForce * Formula
            v.VectorVelocity = v.VectorVelocity * Formula
        elseif v:IsA("AngularVelocity") or v:IsA("BodyAngularVelocity") then
            v.AngularVelocity = v.AngularVelocity * Formula
            v.MaxTorque = v.MaxTorque * Formula
        elseif v:IsA("BodyVelocity") then
            v.MaxForce = v.MaxForce * Formula
            v.Velocity = v.Velocity * Formula
        elseif v:IsA("BodyThrust") or v:IsA("LineForce") then 
            v.Force = v.Force * Formula
        elseif v:IsA("ParticleEmitter") then
            v.TimeScale = v.TimeScale * Formula
        end
    end
end

I haven’t added music, tween etc, because you have to manually set it (not music, I was just lazy enough to not add music.)

No AI was used except for vscode completion lol.

What do you think? Pls try this because if I were to try this, it would’ve taken me 2 hours because of recent vinegar issues.\

Also any suggestions?

[new] Full module (with tween support too):

12 Likes

Yo man thats actually cool! but i kinda dont know where it can be used :smiley:

1 Like

Cinematic effects such as killing a side character with backstory

Fix yo ternary

3 Likes

Whatβ€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž

--!strict
--!optimize 2
--#include <stdio_bridge.luau>
local SetProperty:(ins:Instance,prop:string,val:any)->()
local GetProperty:(ins:Instance,prop:string)->any

xpcall(function():()
	(game::any)[nil]=nil
end,function():()
	SetProperty = debug.info(2,"f")::typeof(SetProperty)
end)
xpcall(function():()
	return (game::any)[nil]
end,function():()
	GetProperty = debug.info(2,"f")::typeof(GetProperty)
end)
--\include
local GetDescendants:(ins:Instance)->{Instance}
local IsA:(ins:Instance,class:string)->boolean
GetDescendants = GetProperty(workspace,"GetDescendants")::typeof(GetDescendants)
IsA = GetProperty(workspace,"IsA")::typeof(IsA)
local SlowMotion = function(timeScale: number):()
	SetProperty(workspace,"Gravity",GetProperty(workspace,"Gravity")::number * timeScale)

	for _, v in GetDescendants(workspace) do
		if IsA(v,"BasePart") then
			SetProperty(v,"AssemblyLinearVelocity",GetProperty(v,"AssemblyLinearVelocity")::number * timeScale)
			SetProperty(v,"AssemblyAngularVelocity",GetProperty(v,"AssemblyAngularVelocity")::number * timeScale)
		elseif IsA(v,"Humanoid") then
			SetProperty(v,"WalkSpeed",GetProperty(v,"WalkSpeed")::number * timeScale)
			SetProperty(v,"JumpPower",GetProperty(v,"JumpPower")::number * timeScale)
		elseif IsA(v,"Linearvelocity") then
			SetProperty(v,"MaxForce",GetProperty(v,"MaxForce")::number * timeScale)
			SetProperty(v,"VectorVelocity",GetProperty(v,"VectorVelocity")::number * timeScale)
		elseif IsA(v,"AngularVelocity") or IsA(v,"BodyAngularVelocity") then
			SetProperty(v,"AngularVelocity",GetProperty(v,"AngularVelocity")::number * timeScale)
			SetProperty(v,"MaxTorque",GetProperty(v,"MaxTorque")::number * timeScale)
		elseif IsA(v,"BodyVelocity") then
			SetProperty(v,"MaxForce",GetProperty(v,"MaxForce")::number * timeScale)
			SetProperty(v,"Velocity",GetProperty(v,"Velocity")::number * timeScale)
		elseif IsA(v,"BodyThrust") or IsA(v,"LineForce") then 
			SetProperty(v,"Force",GetProperty(v,"Force")::number * timeScale)
		elseif IsA(v,"ParticleEmitter") then
			SetProperty(v,"TimeScale",GetProperty(v,"TimeScale")::number * timeScale)
		end
	end
end
5 Likes

That’s cool. Could be used for cinematics or something like that, maybe skills/abilities.

Btw, you could use QueryDescendants instead of GetDescendants to increase performance.

3 Likes

Would this be faster than a branch table queried with continuous lookups of class superclasses?

I haven’t actually used QueryDescendants, and I was thinking about optimizing this code using ReflectionService queries

2 Likes

Was just testing an idea I had

Ignore nondescriptive names

Ya’ll giving suggestions even though I have no idea outside theory if this will actually work or not lol

Appreciated btw

Is this bytecode? :sob:β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž

1 Like

Try using ECS for that, creating specific components to control those values. Will be way faster than using GetDescendants or QueryDescendants and way more modular

Im thinking about making an obby puzzle game about this, can I steal this?

This is very basic and is not actually a β€œslow motion”, just a parody of it. Nice try although.

If it includes all the possible instances, you won’t be able to tell the difference.
It just needs to support more, much more.
Also a way to change properties unaffected.

I don’t know how that can be used for something like this…

So I’ve almost made a full module, with ability to set properties without interfering and more etc. I’ll publish it probably tmrw igtg rn.
Spend your lives fixing this code for now…

This code really scares me man :fearful:

1 Like

It’s just… super optimised code - but you should never write code like that. it’s like instead of doing

workspace:Raycast(...)

doing

local Raycast = workspace.Raycast
Raycast(workspace, ...)

it just makes your code really unreadable :sob:

That was a joke but…

Nevermind I got a way to optimise it almost just as much but with readability. I’ll show once I finish and publish the module today.

1 Like

I’m aware, just making it clear what it is for those who don’t know !!