Here is the code :
local UIS = game:GetService("UserInputService")
local camerapart = game.Workspace:WaitForChild("CameraPart")
local speed = -5
local laneWidth = 8
local currentLane = 2
UIS.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.A then
-- Move left
currentLane = math.max(currentLane - 1, 1)
elseif input.KeyCode == Enum.KeyCode.D then
-- Move right
currentLane = math.min(currentLane + 1, 3)
end
end
end)
game:GetService("RunService").Heartbeat:Connect(function()
local targetPosition = (currentLane - 2) * laneWidth
local currentPosition = camerapart.Position.X
local netvalue = targetPosition - currentPosition
local movement = math.clamp(netvalue, -0.9, 0.9)
camerapart.Position = camerapart.Position + Vector3.new(movement, 0, speed)
end)
the code works fine, but after a certain distance the camera part goes back to its original position for some reason and starts to move again.
The video i provied shows the issue
** You are now Level 3! **