Yet in the properties, the orientation is changing.
Here’s my code
local part = game.Workspace.eggtest
local camera = workspace.CurrentCamera
local DurationOfTween = .75
local IsNegative = false
game:GetService("RunService"):BindToRenderStep("...", Enum.RenderPriority.Camera.Value + 1, function()
part.CFrame = camera.CFrame * CFrame.new(0, 0, -8)
while true do
if IsNegative == false then
part.Orientation = Vector3.new(15, 0, 0)
wait(.75 / 15)
wait(0.05)
part.Orientation = Vector3.new(-15, 0, 0)
wait(.75 / 15)
wait(0.1)
end
end
end)
You should not (cannot!) use wait in a function that is to be run every-frame, as that will cause slowdowns and other problematic issues.
When using BindToRenderStep (and similar), the function, that would be executed every-frame, MUST do whatever it should do in as little time as possible, without doing any delays nor any artificial waiting.
It is explicitly stated for the BindToRenderStep documentation that:
Make sure that any code called by BindToRenderStep runs quickly and efficiently. If code in BindToRenderStep takes too long, then the game visuals will be choppy.
So if you still want to use BindToRenderStep, to do a shaking animation, I would suggest the below approach instead, containing no wait statements, as it instead counts the number of times it is called (i.e. frames), to simulate a “wait” before inverting the orientation:
local RunService = game:GetService("RunService")
local renderStepName = "ShakeEgg" -- A unique identification
local function StopShaking()
pcall(function()
RunService:UnbindFromRenderStep(renderStepName)
end)
end
local function StartShaking(part)
StopShaking() -- Failsafe, in case developer forgot to stop the previous shaking
part.CFrame = camera.CFrame * CFrame.new(0, 0, -8)
local offsetX = 15
local frameCount = 0
RunService:BindToRenderStep(renderStepName, Enum.RenderPriority.Camera.Value + 1, function()
frameCount = frameCount - 1
if frameCount <= 0 then
offsetX = -offsetX -- Invert the offsetX, to simulate shaking
part.Orientation = Vector3.new(offsetX, 0, 0)
frameCount = 3 -- Number of frames to skip, before inverting the orientation again
end
end)
end