Time Scale Framework Tutorial

What Is Time Scale Framework? :zap:

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


Setup :hourglass:

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


Whitelisting Objects :clipboard:

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 “TimeScaleWhitelist”.

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 :scroll:

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

local SlowedTimeScale = 5
local SpeedTimePlayers = {}

local ToggleSpeedEvent = Instance.new("RemoteEvent")
ToggleSpeedEvent.Name = "ToggleSpeed"
ToggleSpeedEvent.Parent = game:GetService("ReplicatedStorage")
ToggleSpeedEvent.OnServerEvent:Connect(function(Player)
	print("==========")
	local TimeScale = 1
	
	SpeedTimePlayers[Player.UserId] = if SpeedTimePlayers[Player.UserId] then nil else true
	
	local SpeedTimePlayersCount = 0
	
	for UserId, _ in SpeedTimePlayers do
		SpeedTimePlayersCount += 1
	end
	
	TimeScale = if SpeedTimePlayersCount == 0 then 1 else SlowedTimeScale
	
	if Player.Character then
		if Player.Character:FindFirstChildOfClass("Humanoid") then
			if SpeedTimePlayers[Player.UserId] then
				game:GetService("CollectionService"):RemoveTag(Player.Character:FindFirstChildOfClass("Humanoid"), "TimeScaleWhitelist")
				print(Player.Name .. " joined speed time!")
			else
				game:GetService("CollectionService"):AddTag(Player.Character:FindFirstChildOfClass("Humanoid"), "TimeScaleWhitelist")
				print(Player.Name .. " left speed time!")
			end
		end
	end
	
	print("New time scale: " .. tostring(TimeScale))
	game:GetService("ReplicatedStorage").TimeScaleUtilities:SetAttribute("TimeScale", TimeScale)
end)

game:GetService("Players").PlayerRemoving:Connect(function(Player)
	SpeedTimePlayers[Player.UserId] = nil
end)

game:GetService("Players").PlayerAdded:Connect(function(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	
	local Humanoid = Character:WaitForChild("Humanoid")
	if Humanoid then
		game:GetService("CollectionService"):AddTag(Humanoid, "TimeScaleWhitelist")
	end
	
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		if not Humanoid then return end
		game:GetService("CollectionService"):AddTag(Humanoid, "TimeScaleWhitelist")
	end)
end)

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

local function ToggleSpeed(ActionName, InputState, InputObject)
	if InputState == Enum.UserInputState.Begin or InputState == Enum.UserInputState.End then
		game:GetService("ReplicatedStorage").ToggleSpeed:FireServer()
	end
end

game:GetService("ContextActionService"):BindAction("ToggleSpeed", ToggleSpeed, true, Enum.KeyCode.LeftShift, Enum.KeyCode.ButtonR1)


Play Around With Settings :gear:

If you would like to change the settings for how much time changes, edit the SlowedTimeScale attribute attributed to the TimeScaleFramework folder in the ServerScriptService.


Conclusion :wave:

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:

41 Likes

But i see Lightning Tag and WhiteList Tag and i only cant understand Waht Lightning tag for

1 Like

Hello,
The lightning is not important for the Time Scale Framework and only serves a purpose for the lightning particle effects on the player.
Apologies for the confusion caused.

1 Like

If It wasn’t IMPORTANT so why did you make that ?
Or Because it’s making the particles normaly and not slowed time using “Time thing that i saw in the particles thats not speed its time scale ???”
Sorry for asking to much (•_•)

I didn’t have to add in the lightning particles or anything, I just added it for some flair. I have now removed them to help simplify the place file for developers looking to use the Time Scale Framework.
Hope this helps clear up any confusion.

1 Like

the place used to be called speedster test or something i don’t remember that well, so it was supposed to be flash lightning effect before the place became a time scale framework demonstration

1 Like

It was testing for a game I’m working on then I decided to open source the framework so other people can use it & work on it. This is where I renamed it & made it more general purpose so it would be easy to fit in to a wide range of projects other people might be working on.

The local script is not detecting my input, so I just made my own toggle but “InvokeServer” can’t be set to a Remote event, also you kept calling the toggle a remote function but set it as a remote event… IM SO CONFUSED!!!

Sorry for the confusion. Thank you for pointing out the naming issues. I’ll get those resolved as soon as I can.

As for the functionality issues I haven’t taken a look at this tutorial in a long while so I will revisit it when I update the variable name & change anything else in this tutorial where appropriate.

My apologies again for any confusion caused.

So I ended up using the test place’s code and in there it seemed that as soon as a player presses shift the animations slow down, when I used it, I have to wait for the animation to finish before the slowness takes action. I don’t know if you know how to fix this but just let me know

Sorry for the long delay - been just a bit busy over the summer.

Apologies again for the confusion in the tutorial code. I’ve updated the tutorial with fixed code. I’m not quite sure on how I got it muddled up in the first place. :sweat_smile:

There will be more updates to both the framework & tutorial soon now that I have some free time to flesh it out more. The rewritten tutorial I’m working on will provide you with a much better understanding of how to use the framework. :slight_smile:

Thank you!

lol its been a minute, I’ll have this saved for next time because its a really useful model!