Issue with my camera movement script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the camera to move when you left‑click and drag the mouse.
  2. What is the issue? Include screenshots / videos if possible!
    I’m trying to make a camera movement system for my pc building simulator game where when you left click in drag the mouse the camera moves in the mouse direction but jumps to the other side of the pc case instead of the front of the pc case like on the video in it does not let you move the camera when left clicking in dragging the mouse
  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    I tried using Run Service I tried using CFrame angel

hers the camera client script

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local CameraRemote = ReplicatedStorage:WaitForChild("CameraRemote")
local RotateCaseRemote = ReplicatedStorage:WaitForChild("RotateCaseRemote")

local inspecting = false
local caseModel = nil

local targetRotationY = 0
local currentRotationY = 0

local distance = 4

CameraRemote.OnClientEvent:Connect(function(cameraPoint, caseRef)
	inspecting = true
	caseModel = caseRef

	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = cameraPoint.CFrame

	local hum = player.Character:FindFirstChild("Humanoid")
	if hum then
		hum.WalkSpeed = 0
		hum.JumpPower = 0
	end
end)

RunService.RenderStepped:Connect(function(char)
	if not inspecting or not caseModel or not caseModel.PrimaryPart then return end
	
	currentRotationY +=  (targetRotationY - currentRotationY) * 0.15
	
	local pivot = caseModel.PrimaryPart.CFrame
	local rot = CFrame.Angles(0, math.rad(currentRotationY), 0)
	local offset = CFrame.new(0, 0, distance)
	
	camera.CFrame = pivot * rot * offset
end)



UserInputService.InputChanged:Connect(function(input)
	if not inspecting then return end
	if input.UserInputType ~= Enum.UserInputType.MouseMovement then return end
	if not UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then return end
	
	local delta = input.Delta.X
	targetRotationY -= delta * 0.5
	
	RotateCaseRemote:FireServer(targetRotationY)
end)

hers the pc case server script

local case = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local placementValue = ReplicatedStorage:WaitForChild("PlacementCFrame")
local remote = ReplicatedStorage:WaitForChild("CarryRemote")
local CameraRemote = ReplicatedStorage:WaitForChild("CameraRemote")
local RotateCaseRemote = ReplicatedStorage:WaitForChild("RotateCaseRemote")

local isPlaced = false

remote.OnServerEvent:Connect(function(player, action, target)

	local character = player.Character
	if not character then return end

	local rightHand = character:FindFirstChild("RightHand") or character:FindFirstChild("Right Arm")
	if not rightHand then return end

	local carryMotor = rightHand:FindFirstChild("CarryMotor")
	

	if action == "place" then

		if not carryMotor then return end

		if placementValue.Value == CFrame.new() then
			return
		end

		local tablePos = Vector3.new(47.481, 5.828, 32.217)
		local distanceToTable = (character.PrimaryPart.Position - tablePos).Magnitude
		if distanceToTable > 8 then
			return
		end

		carryMotor:Destroy()
		case:SetPrimaryPartCFrame(placementValue.Value)

		for _, part in ipairs(case:GetDescendants()) do
			if part:IsA("BasePart") then
				part.CanCollide = true
				part.Massless = false
			end
		end

		placementValue.Value = CFrame.new()

		local outline = workspace:FindFirstChild("ActiveOutline")
		if outline then outline:Destroy() end
		
		isPlaced = true
		case:SetAttribute("Placed", true)

		return
	end
	
	if action == "inspect" then
		if isPlaced and not carryMotor and target:IsDescendantOf(case) then
			local cameraPoint = case:FindFirstChild("CameraPoint")
			if cameraPoint then
				CameraRemote:FireClient(player, cameraPoint, case)
			end
		end
	end

	if action == "pickup" and target:IsDescendantOf(case) then

		if carryMotor then 
			return 
		end
		
		if isPlaced and target:IsDescendantOf(case) then
			local cameraPoint = case:FindFirstChild("CameraPoint")
			if cameraPoint then
				CameraRemote:FireClient(player, cameraPoint, case)
			end
			return
		end
		
		if target:IsDescendantOf(case) then
			local distance = (case.PrimaryPart.Position - character.PrimaryPart.Position).Magnitude
			if distance > 6 then return end

			isPlaced = false
			case:SetAttribute("Placed", false)

			for _, part in ipairs(case:GetDescendants()) do
				if part:IsA("BasePart") then
					part.CanCollide = false
					part.Massless = true
				end
			end

			case:SetPrimaryPartCFrame(rightHand.CFrame * CFrame.new(0, -1, -1.5))

			local motor = Instance.new("Motor6D")
			motor.Name = "CarryMotor"
			motor.Part0 = rightHand
			motor.Part1 = case.PrimaryPart
			motor.C0 = CFrame.new(0, -1, -1.5)
			motor.Parent = rightHand
	    end
	end
end)

RotateCaseRemote.OnServerEvent:Connect(function(player, rotY)
	if isPlaced then
		local basePos = case.PrimaryPart.CFrame.Position
		case:SetPrimaryPartCFrame(
			CFrame.new(basePos) * CFrame.Angles(0, math.rad(rotY), 0)
		)
	end
end)

1 Like

If the remote is firing and the server successfully received it, then it isnt doing anything because isPlaced is false and never changes

A better solution is probably to just rotate the case on the client script because it will be much smoother. If you want the case to rotate for everyone then fire the remote less frequently and then make the server tell every other client to tween the rotation on their side