Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

camera script glitchy?

player = game.Players.LocalPlayer
char = player.Character
cam = game.Workspace.CurrentCamera

local part = Instance.new("Part")
part.Transparency = 1
part.Parent = game.Workspace
part.Anchored = true
part.Position = Vector3.new(30,20,30)
cam.CameraSubject = part
wait(1) -- so that i have time to fall from the sky onto the baseplate
while wait() do
		local h = char.Torso.Position
		part.Position = Vector3.new(h.X,20,h.Z)
	end

the script above makes a part above my head, end puts the camera in it. the only problem is that if i set my walkspeed high enough, the camera will be really jumpy trying to be at the position. i tried using.Changed, but for some reason, it never works for me. how do i have the parts position not be jumpy at high speeds?

1 answer

✓ Accepted answer

You'll need the part to change position each time that the screen updates. You can use RunService's BindToRenderStep function to do this.

player = game.Players.LocalPlayer
char = player.Character
cam = game.Workspace.CurrentCamera

local part = Instance.new("Part")
part.Transparency = 1
part.Parent = game.Workspace
part.Anchored = true
part.Position = Vector3.new(30,20,30)
cam.CameraSubject = part
wait(1) -- so that i have time to fall from the sky onto the baseplate
-- "move part" : The name of the bind, can be used with UnbindFromRenderStep to stop the function
-- 2000 : The priority, higher values run after smaller values. 2000 should make it run last
game:GetService("RunService"):BindToRenderStep("move part", 2000, function()
	 local h = char.Torso.Position
	 part.Position = Vector3.new(h.X,20,h.Z)
end)

1 comment

0

i set the 2000 to 20, and it worked! I've never heard about this function before, thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.