Trying to replicate viewmodels to the server

by the way this is my first post so please bear with me here.

What do i want to achieve?

i have this viewmodel system i’ve been working on im pretty much done with it in terms of client sided stuff, but not really with server sided things i’m currently trying to make a system where if a player equips a tool it will replicate it’s viewmodel to the player’s character

i still want the full movements but what i am looking for is something that does replicate the viewmodel to the player’s character but constantly changes the player’s arm’s to replicate the movements of the arms in the viewmodel

Viewmodel in question:
(by the way does it look cool? im only a beginner at blender animations)

The Issue?

I couldn’t really figure out how to replicate the viewmodel to the server efficiently as welding it seems to mess with the physics of the player and using something like a loop or RunServ.Stepped makes the viewmodel delayed from the player’s position, i’m not really looking for that

What Have i tried so far?

I Tried making a system that would only replicate the viewmodel to the other clients and not the server by using FireAllClients() and having the player’s arm become basically not there then i would handle the event stuff in a localscript located in StarterPlayerScripts which worked great but it had a small issue, when a player shoots a bullet which would be on the server it wouldn’t detect the arms on the viewmodel

ill throw an example as at this time i do not have access to the code i wrote

-- Server Sided Reciever

local ExampleEvent = game.ReplicatedStorage.Event

ExampleEvent.OnServerEvent:Connect(function(plr, ViewmodelName)
	ExampleEvent:FireAllClients(plr, ViewmodelName)
	
	-- imagine down here some lines that would basically disable the arms of the player
end)

-- LocalSript VM Handler

local ExampleEvent = game.ReplicatedStorage.Event

ExampleEvent.OnClientEvent:Connect(function(Target, ViewmodelName)
	local Model = game.ReplicatedStorage.Viewmodels:FindFirstChild(ViewmodelName)
	if not Model then return end
	
	local Viewmodel = Model:Clone()
	Viewmodel.Parent = Target.Character
	
	local Loop
	Loop = game:GetService("RunService").RenderStepped:Connect(function()
		Viewmodel.PrimaryPart:PivotTo(Target.Character.Head)
	end)
end)

-- Bullet Module

function Bullet(StartCF)
	local Bullet = Instance.new("Part")
	Bullet.CFrame = StartCF

	Bullet.Name = "Bullet"

	Bullet.Parent = workspace.Debris.Bullets
	Bullet.Size = Vector3.new(0.25, 0.25, 1)
	Bullet.Anchored = false
	Bullet.CanCollide = false
	Bullet.CanTouch = true
	Bullet.Color = Color3.fromRGB(255, 255, 127)
	Bullet.Material = Enum.Material.Neon
	Bullet.Massless = false

	game:GetService("Debris"):AddItem(Bullet, 5)

	local attach = Instance.new("Attachment", Bullet)
	local VectorFor = Instance.new("VectorForce", Bullet)
	VectorFor.Attachment0 = attach
	VectorFor.Force = Vector3.new(0, -Bullet:GetMass() / 5, 0)
	VectorFor.RelativeTo = Enum.ActuatorRelativeTo.World

	Bullet.AssemblyLinearVelocity = StartCF.LookVector * 500
	
	local result = workspace:Raycast() -- Raycast Started from StartPos

	if result then
		Bullet:Destroy()

		local hum = result.Instance.Parent:FindFirstChild("Humanoid")

		if hum then
			hum:TakeDamage(5)
		end
	end
end

and thats pretty much it

When you weld the arms, do you set all BasePart descendants to be massless? If you did, physics shouldn’t have that sort of effect. Having a system to continuously replicate the client viewmodel is also not that great of an idea. You can just have the viewmodel be the third-person (world) model.

If your viewmodel is named a specific way (e.g. “Left Arm” and “Right Arm”) you could potentially just play the same animation directly on the character, though this probably isn’t likely.

Exact positions are kind of … bad … if you weren’t looking for any of the above implementations. It’s probably a better idea to have a separate set of animations for character v. viewmodel, though it might be more work.

is the viewmodel only the gun? if not, i dont think thats possible without it looking janky. These are called viewmodels for a reason :thinking:

nevermind. How To Replicate Viewmodel Arm Movement To Real Arm, this might help

I looked at that Post many times yet i didn’t find a solution to my problem

I decided to go with the welding system but when i weld the viewmodel it still messes with the physics of the player even if i have all parts to be massless

	-- handeled with a remote event to the server
	
	local VmModel = game.ReplicatedStorage.Viewmodels:FindFirstChild(VMName)
	if not VmModel then return end
	
	local char = plr.Character
	
	local Viewmodel = VmModel:Clone()
	Viewmodel.Parent = char
	
	for _, Part: Part in pairs(Viewmodel:GetDescendants()) do
		if Part:IsA("BasePart") then
			Part.Anchored = false
			Part.Massless = true
		end
	end
	
	Viewmodel.PrimaryPart:PivotTo(char.Head.CFrame * CFrame.new(0.15, -0.15, -0.15))
	
	local Weld = Instance.new("Weld", char.Head)
	Weld.Name = "ViewmodelWeld"
	
	Weld.Part0 = Weld.Parent
	Weld.Part1 = Viewmodel.PrimaryPart

Consider not welding it and forcing each player to set it’s position where it’s supposed to be on .RenderStepped

I’d rather use weaponry’s developer method if i were you, his username is Headstack if I remember correctly, the post should be under Community Tutorials category

Thank you for the suggestion but i have a simple question

is this the post you are talking about?: How to animate Tool Parts (Guns, Knifes etc.)

if not can you please give me a link to it

Yes, i usually prefer this method over others because I have 1 rig and 1 animation for both first person and third person, you can either code arms visibility yourself or use something like EasyFirstPerson I like it because you can configure offset and it adds configurable sway on strafe, camera movement, jump. It also has an AimOffset that you can tween to create simple iron sight aiming. It’s somewhere in community resources

It actually creates some kind if viewmodels, though these are first person only and replicate real arms, works great with the tutorial (no extra setup needed if using the method)

I found a weird way to stop the viewmodel from messing with the character physics althought its kinda weird

	if humanoid then
		humanoid.PlatformStand = true
		humanoid.HipHeight = 0
		
		for _, State in pairs(Enum.HumanoidStateType:GetEnumItems()) do
			if State ~= Enum.HumanoidStateType.Physics then
				humanoid:SetStateEnabled(State, false)
			end
		end
		
		humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	end

by the way the issue that was making the viewmodel do that in the first place was because the viewmodel had a Humanoid instance

1 Like