Recently I found an issue with my gun system, the problem is that the viewmodel movement only plays on the Client and doesn’t replicate to server
Client Script
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera
local ReplicatedStorage = game:GetService("ReplicatedStorage")
if not character:FindFirstChild("Torso") then
error("Player's Humanoid is not an R6 rig.")
return
end
local head = character:WaitForChild("Head")
local torso = character:FindFirstChild("Torso")
local leftArm = character:FindFirstChild("Left Arm")
local rightArm = character:FindFirstChild("Right Arm")
local neck = torso:FindFirstChild("Neck")
local leftShoulder = torso:FindFirstChild("Left Shoulder")
local rightShoulder = torso:FindFirstChild("Right Shoulder")
local defaultHeadC1 = neck.C1
local defaultLeftArmC1 = leftShoulder.C1
local defaultRightArmC1 = rightShoulder.C1
local defaultHeadC0 = neck.C0
local defaultLeftArmC0 = leftShoulder.C0
local defaultRightArmC0 = rightShoulder.C0
local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")
local spring = require(script.spring)
local mouseDeltaDivision = 200
local swayOffset = CFrame.new()
local movementOffset = CFrame.new()
local swaySpring = spring.create()
local movementSpring = spring.create()
local transparency = 0
local function setTransparency(part)
if part and part:IsA("BasePart") and (part.Name=="Left Arm" or part.Name=="Right Arm") then
part.LocalTransparencyModifier = transparency
part:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function(property)
part.LocalTransparencyModifier = transparency
end)
end
end
local function inFirstPerson()
local dist = (camera.CFrame.Position - (root.Position + Vector3.new(0,1.5,0))).Magnitude
return dist < 1
end
local function getBobbing(addition,speed,modifier)
return math.sin(tick()*addition*speed)*modifier
end
local function renderStepped(dt)
local speed = 1.5 * (humanoid.WalkSpeed / 16)
local modifier = 4
local mouseDelta = userInputService:GetMouseDelta()
local walkCycle = Vector3.new(getBobbing(10,speed,modifier),getBobbing(5,speed,modifier), 0) * dt
swaySpring:shove(Vector3.new(mouseDelta.x / mouseDeltaDivision,mouseDelta.y / mouseDeltaDivision))
if script:GetAttribute("WalkCycle") == true then
movementOffset = movementSpring:update(dt)
else
movementOffset = CFrame.new()
end
if script:GetAttribute("ViewmodelSway") == true then
swayOffset = swaySpring:update(dt)
else
swayOffset = CFrame.new()
end
local movementCF = CFrame.new()
movementCF = CFrame.new(movementOffset.y, movementOffset.x, movementOffset.z)
if humanoid.MoveDirection.Magnitude > 0 then
movementSpring:shove(walkCycle)
else
movementSpring:shove(Vector3.new())
end
if inFirstPerson() then
transparency = script:GetAttribute("ArmTransparency")
--[[
local cf = CFrame.Angles(math.pi/2, 0, 0)
local x, y, z = cf:ToEulerAnglesYXZ()
local newCF = CFrame.Angles(x, y, z)
--]]
local torsoX,torsoY,torsoZ = torso.CFrame:ToEulerAnglesYXZ()
local cameraX, cameraY, _ = camera.CFrame:ToEulerAnglesYXZ()
local viewmodelOffset = script:GetAttribute("ViewmodelOffset")
local torsoRot = CFrame.Angles(0,torsoY,torsoZ)
local cameraPos = CFrame.new(viewmodelOffset.X,viewmodelOffset.Y,-viewmodelOffset.Z)
local cameraRot = CFrame.Angles(0, -cameraY, 0)
local swayCF = CFrame.Angles(swayOffset.y, swayOffset.x, swayOffset.x/2)
local camCF = camera.CFrame * cameraPos * cameraRot * torsoRot * swayCF * movementCF
rightShoulder.C0 = torso.CFrame:inverse() * (camCF * CFrame.Angles(0,math.rad(90),0) * CFrame.new(0,-1,1))
leftShoulder.C0 = torso.CFrame:inverse() * (camCF * CFrame.Angles(0,math.rad(-90),0) * CFrame.new(0,-1,1))
else
transparency = 0
neck.C1 = defaultHeadC1
leftShoulder.C1 = defaultLeftArmC1
rightShoulder.C1 = defaultRightArmC1
neck.C0 = defaultHeadC0
leftShoulder.C0 = defaultLeftArmC0
rightShoulder.C0 = defaultRightArmC0
end
end
for _,v in pairs(character:GetChildren()) do
setTransparency(v)
end
runService.RenderStepped:Connect(renderStepped)