Moving part is glitchy

So i have this script where it moves the part, but the part(cam) is very glitchy as a move the player around the map, is there anyway to fix this? The script is in serverscriptservices. the part is a regular part in workspace. Pls help.

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Char)
local cam = game.Workspace.CameraPart --the part
while true do
cam.Position = Char.HumanoidRootPart.Position + Vector3.new(0, 5, -10)
cam.CFrame = CFrame.new(cam.Position, Char.HumanoidRootPart.Position)
wait()
end
end)
end)

2 Likes

What do you mean by Glitchy? Do you have a screen record

1 Like

Im guessing you have anchored the part, right?

If you want it to glide smoothly, not choppy, you can use TweenService to achieve a smooth effect.

If you want the part to update faster, consider using task.wait() instead wait or you could use RunService.Heartbeat:Connect()

1 Like

like the part that i want to move it like not moving smoothly

can you explain to me how tweenservice works?

1 Like

Well, I’m kinda lazy so here is a tutorial on how TweenService works:
https://www.youtube.com/watch?v=SySp1wTsCkY

Basically how you can use tweenservice is, instead of setting the cam.CFrame like so, do it using tweenservice.

Also, this is very important. When moving the camera, make sure to set the CameraType to scriptable. This might have been your issue. You can do it like this: cam.CameraType = Enum.CameraType.Scriptable. And when you want the camera to be back to normal, do: Enum.CameraType.Custom.

1 Like

the tween service works but it moves back and forth, how can i fix it?

1 Like

cam.Position = Char.HumanoidRootPart.Position + Vector3.new(0, 0.5, -1) - this only made the cam closer to the player

1 Like

set the repeatCount parameter of TweenInfo to 0

check the documentation here

1 Like

ok, so i made this script, but there is a new problem is that it doesnt check where the player is.

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Char)
local cam = game.Workspace.CameraPart

	local ts = game:GetService("TweenService")


	local tweeninfo = TweenInfo.new(
		2, 
		Enum.EasingStyle.Sine, 
		Enum.EasingDirection.Out,
		0,
		true
	)

	
	local tween = ts:Create(cam, tweeninfo, {Position = Char.HumanoidRootPart.Position + Vector3.new(0, 5, -10)})
	
	
	while true do
		tween:Play()
		wait()
	end
end)

end)

1 Like