SurfaceGui Image button stutter while tweening

localscript:

local SCALE = 0.02

game:GetService("RunService").RenderStepped:Connect(function()
	local sizeX = mouse.ViewSizeX
	local sizeY = mouse.ViewSizeY

	local mouseX = (mouse.X-mouse.ViewSizeX/2) * SCALE
	local mouseY = (mouse.Y-mouse.ViewSizeY/2) * SCALE
	
	local targetCFrame = CFrame.new(HRP.CFrame.Position) * CFrame.new(0,2,0) * CFrame.Angles(workspace.CurrentCamera.CFrame:ToEulerAnglesXYZ()) * CFrame.Angles(0,math.rad(mouseX),0) * CFrame.Angles(math.rad(mouseY),0,0)
	
	TweenService:create(workspace["3DGui"].MenuObj,TweenInfo.new(.05,Enum.EasingStyle.Linear),{CFrame = targetCFrame}):Play()
end)

( ^^^ Extracted from big script, let me know if you need explanation of any arguments)
(the part im moving is gui’s adornee)

rotations are smooth, but gui’s adornee part start stuttering for some reason when player walk
It’s 100% caused of using tween every frame but i kinda dont know how to make part move smooth without tweenservice (tried lerp, didnt work smh)

showcase:

How can I fix it?

Have you tried Heartbeat or PostSimulation instead of RenderStepped

Literally gave me the same result :confused:

You might have to unanchor the part and set its network owner to the player. Not sure if it’ll work with tweens instead of physics though

Now the part just disappear in 5 seconds after joining the place :+1:

I edited it with lerping, sluttering should be fixed too:

local camera = workspace.CurrentCamera

local SCALE = 0.02
local LERP_SPEED = 25
local obj = workspace:WaitForChild("3DGui"):WaitForChild("MenuObj")

function getRCF()
	if player.Character == nil then
		return nil
	end
	return CFrame.new(player.Character:GetPivot().Position) * CFrame.new(0, 2, 0)
end
function getMCF()
	if mouse == nil then
		return nil
	end
	local sizeX = mouse.ViewSizeX
	local sizeY = mouse.ViewSizeY

	local mouseX = (mouse.X - mouse.ViewSizeX / 2) * SCALE
	local mouseY = (mouse.Y - mouse.ViewSizeY / 2) * SCALE

	return CFrame.Angles(camera.CFrame:ToEulerAnglesXYZ()) * CFrame.Angles(0, math.rad(mouseX), 0) * CFrame.Angles(math.rad(mouseY), 0, 0)
end
obj.CFrame = getRCF() or CFrame.new()

game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
	local rcf, mcf = getRCF(), getMCF()
	if rcf == nil or mcf == nil then
		return
	end
	obj.CFrame = (obj.CFrame.Rotation + rcf.Position):Lerp(rcf * mcf, deltaTime * LERP_SPEED)
end)

(test place Part. - Roblox)

1 Like

i havent messed around with this but, have you tried BindToRenderStep? try set the priority really high so it fires after every calculation (like firing after camera calculations)
if i remember well, lower priorities fire first, try making it higher than the camera priority

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.