I have made a view model for a flashlight item on the client side but I want everyone in the server to see the positions of each others arms in the view model.
I am not quite sure on how to go about this but I have seen it in other games like Phantom Forces and would like something similar.
(Also if anyone knows how to move the players head to where their camera is looking on server side that would be very helpful)
Local Script (Inside flashlight tool)
local tool = script.Parent
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local rs = game:GetService("RunService")
local leftArm = char:WaitForChild("Left Arm")
local rightArm = char:WaitForChild("Right Arm")
local uis = game:GetService("UserInputService")
local ViewModel
local equipped = false
local function setArmTransparency(transparency)
rightArm.Transparency = transparency
rightArm.LocalTransparencyModifier = 1 - transparency
wait(0.1)
rightArm.LocalTransparencyModifier = 0
end
tool.Equipped:Connect(function()
equipped = true
if not Camera:FindFirstChild("ViewModel") then
ViewModel = game.ReplicatedStorage.ViewModel:Clone()
ViewModel.Parent = Camera
end
setArmTransparency(1)
end)
tool.Unequipped:Connect(function()
equipped = false
if ViewModel then
ViewModel:Destroy()
ViewModel = nil
end
setArmTransparency(0)
end)
local swayCF = CFrame.new()
rs.RenderStepped:Connect(function()
if player.Character and player.Character:FindFirstChild("Humanoid") and player.Character.Humanoid.Health <= 0 then
if ViewModel then
ViewModel:Destroy()
ViewModel = nil
end
end
if equipped and ViewModel then
ViewModel["Right Arm"].Color = char["Body Colors"].RightArmColor3
if char.Shirt then
ViewModel.Shirt.ShirtTemplate = char.Shirt.ShirtTemplate
end
ViewModel:SetPrimaryPartCFrame(Camera.CFrame)
for _, v in pairs(ViewModel:GetChildren()) do
if v:IsA("BasePart") then
v.CanCollide = false
end
end
local mouseDelta = uis:GetMouseDelta()/50
local swayX = math.clamp(mouseDelta.X, -0.2,0.2)
local swayY = math.clamp(mouseDelta.Y, -0.2,0.2)
swayCF = swayCF:Lerp(CFrame.new(swayX,swayY, 0), 0.3)
Camera.ViewModel:SetPrimaryPartCFrame(Camera.CFrame * swayCF)
end
end)