Equivalent of a tick (0.05 seconds)

Hello everyone.

In Minecraft scripting, there’s 20 ticks per second, meaning each tick is 0.05 seconds.
I saw people say a tick in roblox is the time it is since a date in 1970…?

Is there any equivalent of Minecraft ticks, or 0.05 second measurements?

Sincerely,
-coolguyweir

1 Like

Do you want your script to work each № of time or what i don’t fully understand?

The equivalent of a minecraft tick is RunService.RenderStepped, which can happen every frame up to 60 frames per second

Actually its Heartbeat, it fires every 0.02 seconds. RenderStepped fires, as you said, each frame ur roblox client renders. But i still don’t exactly know what that person means.

You have a valid point, Render Stepped is not certain, he could just do while task.wait (0.05) do if he wants it to be that exact time delay.

1 Like

“tick” in Minecraft refers to the global clock for game mechanics to update by (e.g. Plant growth, Redstone). “tick” in Roblox refers to the global that returns the Unix Time. You can also get this value with os.time, which is considered the more standard version.

In your case, you want to replicate the former. The most accurate way to do this would be to hook up a callback function that counts the DeltaTime that passes for each RunService event.

local RunService = game:GetService("RunService")

local Tick = 0
local TotalTick = 0
local INTERVAL = 0.05

local function UpdateTick(DeltaTime)
	Tick += DeltaTime
	TotalTick += DeltaTime
	
	if Tick >= INTERVAL then
		Tick = 0
		-- Do Stuff
	end
end

-- You could use any RunService event, as each act differently depending on the circumstance
-- See https://create.roblox.com/docs/studio/microprofiler/task-scheduler for more info
RunService.Heartbeat:Connect(UpdateTick)

Although, this is obviously an over-bloated approach. For your use case, you could simply use a while loop that yields every iteration and wrap it inside task.spawn.

local function Loop()
	while true do
		-- Where you yield affects when the loop will initially run
		task.wait(0.05)
		print("Hello, world!")
	end
end

-- To spawn the loop in a separate thread so you can run things after it
task.spawn(Loop)