My custom Mech rig is vibrating in game but not in studio?

I’m working on a mech shooter and I ran into a problem with its movement, In studio it works just fine but when you try it in the game it vibrates like this
https://i.gyazo.com/496bde44ec6311e1b45e7c3f8204c00e.mp4
Heres what it looks like in the studio.
https://i.gyazo.com/31ca7b1aa12a1b363fc3b2a431c1a7d2.mp4
Heres the code behind the movement.

local Character = game.Players.LocalPlayer.Character
local mouse = game.Players.LocalPlayer:GetMouse()
local UserInput = game:GetService("UserInputService")
UserInput.MouseIconEnabled = false
mouse.TargetFilter = workspace
workspace.CurrentCamera.CameraSubject = Character.Body
local last
local Cursor = script.Parent.Main.Cursor
Character.Humanoid.AutoRotate = false
Cursor.Position = UDim2.new(0,mouse.X-(Cursor.Size.X.Offset/2),0,mouse.Y-(Cursor.Size.Y.Offset/2))
local function Update()
	if last ~= mouse.Hit then
		last = mouse.Hit
		local look = mouse.hit.lookVector.Y
		if look < -0.7 then
			look = -0.7
		elseif look > 0.7 then
			look = 0.7
		end
		Character.Hip["HipJoint"].C0 = CFrame.new(Character.Hip["HipJoint"].C0.p) * CFrame.Angles(math.asin(look)+math.rad(180),math.rad(-90),math.rad(180))
		Character.Body.CFrame = CFrame.new(Character.HumanoidRootPart.Position, Vector3.new(mouse.Hit.p.X, Character.HumanoidRootPart.CFrame.Y, mouse.Hit.p.Z))
	end
end
game:GetService("RunService"):BindToRenderStep("updateCharacter", Enum.RenderPriority.Camera.Value-1, Update)

Any ideas?

2 Likes

Server/Movement code?

That’s all the code for the movement up there, I set the mech as “StarterCharacter”

Have you set the NetworkOwnership of each part in the mech rig to the player controlling it?

2 Likes

Could you elaborate? I dont think I have

On the server, you can run a script like this which sets the network ownership of the character’s parts to the player that controls the character once they spawn.

functon onCharacterAdded(characterModel)
    -- Set up the player's rig....
    -- ....
    -- ...

    -- Then finally, set the network ownership of each part in the player
    -- to the character that controls it.
    local player = game.Players:GetPlayerFromCharacter(characterModel)
    for _, v in pairs(characterModel:GetDescendants()) do
        if v:IsA("BasePart") then
            v:SetNetworkOwner(player)
        end
    end
end

(edited, fyi)

But the player is already controlling it… There is nothing that I’ve put on the server side to control the mech, the mech is pretty much just a normal character. Since this is the case, wouldn’t the client already have network ownership?

And let’s say that what I said above isn’t the case, would that mean that the mech would no longer replicate to the server?

I’m not sure. Could you try checking it for yourself? Just print the owner with :GetNetworkOwner() on each part.

:GetNetworkOwner() seems to return nil, but regardless I’ve changed the network ownership and it seems to have stopped, thank you.