RunService:BindToRenderStep() only working on Run?

So I was trying out module scripts and came up with this (MathModule is not part of the issue):image
Caller code:

Modules Code:

SteppedModule Code:

On line 13 of the Caller script, it is supposed to go to the SteppedModule and do RunsService:BindToRenderStep() and line 15 to unbind after waiting 5 seconds. The function passed on is supposed to create parts into workspace.
The problem is that on Run mode it works fine, but on Play, no parts are being created.
Replacing the

with image on the SteppedModule and it prints fine. I’ve spent about an hour trying to rearrange the code but it still only creates parts on Run. Any reason why?

1 Like

In play mode the server isn’t rendering anything so no render steps fire

2 Likes

It says on the dev wiki too:


The only real alternative is using the events that run on the server, at least RunService.Heartbeat. RunService.RenderStepped will definitely not fire, and I don’t know about RunService.Stepped, but it most likely will.

You can achieve a similar workflow to RunService:BindToRenderStep by calling a table of functions each frame on one of its events:

local OnStep = {}

game:GetService("RunService").Heartbeat:Connect(function(dt)
    for _,fn in ipairs(OnStep) do
        fn(dt)
    end
end)

table.insert(OnStep,function()
    Instance.new("Part",workspace)
end)
local index = #OnStep
wait(5)
table.remove(OnStep,index)
1 Like

Stepped and Heartbeat both fire on the server and it’s a choice of whether you want to run your code before or after the Physics step. Heartbeat is the safe option usually.

For OP:
Replace :BindToRenderStep(self.tag, self.prior, self.func) with .Heartbeat:Connect(self.func)

To “unbind” it, you’ll need to store the result, and then call :Disconnect() on it in your unbind function.

2 Likes