Rotating a guiobject with renderstepped

I made a short script to rotate a guiobject at a constant speed.

game:GetService("RunService").RenderStepped:Connect(function(a)
	script.Parent.Rotation = script.Parent.Rotation + (90*a)
end)

This is my first time using renderstepped so Im not sure if I did it properly. It seems to work fine though.

1 Like

To make it run at a constant speed I think you should do something like this

game:GetService("RunService").RenderStepped:Connect(function(a)
	script.Parent.Rotation = script.Parent.Rotation +  (1 / a)
end)

Cause, the higher your fps is, the “lower” your speed.
If your fps is low, your speed will be high.

The thing you did is: the higher your fps, the higher your speed and vice versa.

I hope this helped.

1 Like

Try

local a = 1
local runservice = game:GetService("RunService")
runservice:BindToRenderStep("MyFirstRenderStep",Enum.RenderPriority.Camera.Value+1,function()
script.Parent.Rotation = a
a = a+1
end)
1 Like

it’s spinning at insane speed

1 Like

thanks for the script. the script works well and it’s nice.
but I want the script to be simple as possible and easy to manipulate.

1 Like

Then try changing it by less

local a = 1
local runservice = game:GetService("RunService")
runservice:BindToRenderStep("MyFirstRenderStep",Enum.RenderPriority.Camera.Value+1,function()
script.Parent.Rotation = a
a = a+1.25
end)

your speed is fine. that video was about the guy above you.
I appreciate your script, but I want to use renderstepped cause bindtorenderstep is a bit complicated. I just wanted to check for any flaws in my script.

You should not be using RenderStepped unless you’re updating something that should be updated before a frame renders (e.g. camera or minimal character updates). There is an advisory warning on the Developer Hub about RenderStepped and how it can block the execution of frames as well as hamper performance if you use it inappropriately.

If you aren’t updating the camera or the character, you should look into using Heartbeat. It’s the last of the trio of RunService frame-bound events to run and can be used in mostly all cases of requiring some kind of update where while and wait do not suffice.

4 Likes
game:GetService("RunService").HeartBeat:Connect(function(a)
	script.Parent.Rotation = script.Parent.Rotation + (90*a)
end)

like this then?

1 Like

Heartbeat is one word, but yes, just change the signal you connect to from RenderStepped to Heartbeat.

1 Like

I might’ve misunderstood this thread, but why not GuiObject.Rotation = GuiObject.Rotation + 1?