I have a Viewmodel localscript,it clones the player and leaves a few parts,when the player is in first person it welds an item to the viewmodels right hand, the problem is that the weld is only client side, so it just falls off in the server,im not sure what could fix this
--local VMR = game.ReplicatedStorage.ViewmodelReplicator
local hasbeenequipped = false
--local Debounce = false
local gunweld
local RunService = game:GetService("RunService")
local PhysicsService = game:GetService("PhysicsService")
local Camera = workspace.CurrentCamera
local OFFSET = 0 -- the forward offset
if Camera:FindFirstChild("ViewModel") then
print("destroyed")
Camera.ViewModel:Destroy()
end
local Character = script.Parent
local Animator = Character:WaitForChild("Humanoid"):WaitForChild("Animator")
Character.Archivable = true
local ViewModel = Character:Clone()
ViewModel.Parent = Camera
ViewModel.Name = "ViewModel"
Character.Archivable = false
local ViewModelAnimator = ViewModel.Humanoid.Animator -- // Used to play animations on the ViewModel.
ViewModel.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None -- // Disable name display.
ViewModel.Humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff -- // Disable health display.
ViewModel.Humanoid.BreakJointsOnDeath = false
ViewModel.Head.Anchored = true
ViewModel.PrimaryPart = ViewModel.Head
ViewModel:SetPrimaryPartCFrame(CFrame.new(0, 0,0))
local Offset = Instance.new("CFrameValue", script)
Offset.Name = "Offset"
Offset.Parent = ViewModel
Offset.Value = CFrame.new()
for _, Part in pairs(ViewModel:GetDescendants()) do
if Part:IsA("BasePart") then
Part.Transparency = 1
Part.CastShadow = false
Part.CollisionGroup = "ViewModel"
local LowerName = Part.Name:lower()
if LowerName:match("leg") or LowerName:match("foot") then
Part:Destroy()
elseif not (LowerName:match("arm") or LowerName:match("hand")) then
Part.Transparency = 1
end
elseif Part:IsA("Decal") then
Part:Destroy() -- // Delete all decals
elseif Part:IsA("Accessory") then
Part:Destroy() -- // Delete all accessories.
elseif Part:IsA("LocalScript") then
Part:Destroy() -- // Destroy all scripts.
elseif Part:IsA("Script") then
Part:Destroy() -- // Destroy all scripts
end
end
local LoadedAnimations = {}
Animator.AnimationPlayed:Connect(function(AnimationTrack)
if AnimationTrack:GetAttribute("ViewModelAnimation") ~= true then return end
if not LoadedAnimations[AnimationTrack] then
LoadedAnimations[AnimationTrack] = ViewModelAnimator:LoadAnimation(AnimationTrack.Animation)
end
end)
local function updateAnimations()
for CharAnim, Anim in pairs(LoadedAnimations) do
if CharAnim.IsPlaying ~= Anim.IsPlaying then
if CharAnim.IsPlaying then
Anim:Play()
else
Anim:Stop()
end
end
Anim.TimePosition = CharAnim.TimePosition
Anim:AdjustWeight(CharAnim.WeightCurrent, 0)
end
end
Character.DescendantAdded:Connect(function(Obj)
if Obj:IsA("Weld") and Obj.Name == "RightGrip" then
gunweld = Obj
end
end)
RunService.RenderStepped:Connect(function(dl)
updateAnimations()
ViewModel:SetPrimaryPartCFrame(Camera.CFrame * Offset.Value)-----------------
local ViewModelShirt = ViewModel:FindFirstChildWhichIsA("Shirt") or Instance.new("Shirt", ViewModel)
local CharacterShirt = Character:FindFirstChildWhichIsA("Shirt")
if CharacterShirt then
ViewModelShirt.ShirtTemplate = CharacterShirt.ShirtTemplate
end
for _, Part in pairs(ViewModel:GetChildren()) do
if Part:IsA("BasePart") then
Part.Color = Character[Part.Name].Color
end
end
local dist = (workspace.CurrentCamera.CFrame.Position - Character.Head.Position).Magnitude
if gunweld ~= nil then
if dist > 1 then -- if zoomed out
ViewModel["Left Arm"].Transparency = 1
ViewModel["Right Arm"].Transparency = 1
gunweld.Part0 = Character["Right Arm"]
else -- if zoomed in
ViewModel["Left Arm"].Transparency = 0
ViewModel["Right Arm"].Transparency = 0
gunweld.Part0 = Character["Right Arm"]
end
end
end)
local val = 0
local moving = false
``