Time Scale Framework Tutorial

What Is Time Scale Framework?

Time Scale Framework is something I wrote to allow time to slow down or speed up mid-game.
Learn More


Setup

  1. Grab the model link and insert it into studio.
  2. Move the folder to ServerScriptService.


Whitelisting Objects

This framework works by whitelisting objects. This means that only objects that are tagged with TimeScaleWhitelist will be affected by time scale changes. This is to help with performance as affecting every part in the game (even static ones) wouldn’t be the best for performance so only tag instances that need to be slowed.
The tags in the game use CollectionService. A great way to set these in studio in to use this plugin. Read more about the plugin here!

To whitelist an object so that the framework knows it needs to be affected by time scale changes, tag it with specifically a tag named “WhitelistTimeScale”.

Now that the instances you want whitelisted are set, we can now move on to making it so the player can control time for this demonstration.


Scripts

Insert a Script into ServerScriptService. This script will handle setting up a RemoteFunction which the LocalScript can use to toggle time scale.

local ToggleSpeedFunction = Instance.new("RemoteFunction")
ToggleSpeedFunction.Name = "ToggleSpeed"
ToggleSpeedFunction.Parent = game:GetService("ReplicatedStorage")

ToggleSpeedFunction.OnServerInvoke = function(Player)
	game:GetService("ServerScriptService").TimeScaleFramework.Functions.ToggleSpeed:Invoke(Player)
end

Insert a LocalScript into StarterCharacterScripts. The following code will allow the player to change the toggle the time scale between custom and normal.

game:GetService("UserInputService").InputBegan:Connect(function(InputObject, GameProcessedEvent)
	if InputObject.KeyCode == Enum.KeyCode.LeftShift and not GameProcessedEvent then
		game:GetService("ReplicatedStorage").ToggleSpeed:InvokeServer()
	end
end)
game:GetService("UserInputService").InputEnded:Connect(function(InputObject, GameProcessedEvent)
	if InputObject.KeyCode == Enum.KeyCode.LeftShift and not GameProcessedEvent then
		game:GetService("ReplicatedStorage").ToggleSpeed:InvokeServer()
	end
end)


Play Around With Settings

If you would like to change the settings for how much time speeds up / slows down, edit the settings file which should look like this:

local Settings = {
	AffectedInstances = {
		AlignOrientation = true,
		AlignPosition = true,
		BasePart = true,
		BodyVelocity = true,
		HingeConstraint = true,
		Humanoid = true,
		LineForce = true,
		ParticleEmitter = true,
		PrismaticConstraint = true,
		Sound = true,
		Torque = true,
		VectorForce = true,
	},
	Animations = true,
	SlowedTimeScale = 10,
	TimeScale = 1,
}
return Settings

You can toggle which AffectedInstances are affected even when they have the whitelist tag for easy debugging.
Animations can also be set to true or false which lets you enable or disable if those speed up or slow down with time scale.
You can also set SlowedTimeScale which will let you customise how much you want time to speed up or slow down.

You can also read up more on the APIs in the Documentation which can be found in the folder!


Conclusion

Congratulations! Hopefully now you will understand how to use my time scale framework! :partying_face:
You can see a basic working demonstration place for the time scale framework here:
Time Scale Demonstration

Please let me know if you have any issues with the framework & feel free to post what you’ve managed to create using it! :grin:

5 Likes