#Trying to make a viewmodel that matches players arms

1 messages · Page 1 of 1 (latest)

wraith ferry
#

I'm trying to make a viewmodel that matches the players arms, so far im just trying to put the players right hand on screen, and i made this script, but when i equip the tool, i get flung.

#

Also ignore the sway variables, thats something unrelated

#

I'm using a template script so there might be some unrelated code, just look where it says "tool.Equipped"

quartz imp
#

I’m not quite sure what ur trying to do but turning off massless and can collide might work

wraith ferry
#

Oh wait i figured it out, its because i was anchoring it

wraith ferry
#

Okay but now i have another problem, for some reason the hand isnt moving with the camera

#

Can someone plz help

wicked panther
#

and you're movin the gun but not the arm

#

also it looks like it's a local script, so the arm would only move on the client's side (Other players won't see it), so if it's not for a zombie-style game, but for an FPS, I think the script should be server sided

#

I'd try to do exactly the same thing as with the gun, to the arm , if I were You. I could also try to do it myself, can You paste the code?
in text

wraith ferry
#

Well its supposed to be a viewmodel for only the player to see when in first person\

#

Yeah i can paste the code

#

I'm not able to paste all of it bc of the character limit so I'll leave out the variables at the beginning

#

Or actually I'll just DM you

#

Yeah idk its not letting me paste the code for some reason

wicked panther
wraith ferry
#

local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local uis = game:GetService("UserInputService")

local ViewModel

local equipped = false

tool.Equipped:Connect(function()
equipped = true
game.ReplicatedStorage.ViewModel:Clone().Parent = Camera
for i, v in pairs(character:GetChildren()) do
if v.Name == "RightHand" then
local part = v:Clone()
part.Parent = Camera.ViewModel.Camera
end
end
end)

tool.Unequipped:Connect(function()
equipped = false
ViewModel = Camera.ViewModel
ViewModel:Destroy()
end)

RunService.RenderStepped:Connect(function()
if player.Character.Humanoid.Health <= 0 then
if Camera:FindFirstChild("ViewModel") ~= nil then
workspace.Camera.ViewModel:Destroy()
end
end

if equipped == true then
    if Camera:FindFirstChild("ViewModel") ~= nil then
        Camera.ViewModel:SetPrimaryPartCFrame(Camera.CFrame)
        for i, v in pairs(Camera.ViewModel:GetChildren()) do
            if v:IsA("BasePart") then
                v.CanCollide = false
            end
        end
    end
end

end)

#

Oh there we go

wicked panther
#

kay leme set it up in roblox studio rq

wraith ferry
#

Just saying for it to work in roblox studio you also need to have a viewmodel in replicated storage

wicked panther
#

what is viewmodel?

wraith ferry
#

It sets the viewmodel variable later

#

Yeah this script was kind of a template

wicked panther
#

so it's a boolean value

wraith ferry
#

So it wasn't coded by me

#

Yeah i think so

#

It just means the viewmodel in the camera

#

Its the same as "workspace.Camera.Viewmodel"

devout rootBOT
#

studio** You are now Level 6! **studio

wicked panther
#

can u send a screen shot of how it looks like in studio?

wraith ferry
#

Okay

wicked panther
#

like what icon it has or smthn

wraith ferry
#

Like what the explorer looks like?

wicked panther
#

ye

wraith ferry
#

K one sec

wicked panther
#

k

wraith ferry
#

This is the tool

#

This is Replicated storage

#

Ignore the getmouseposition thing

wicked panther
#

what's inside the ViewModel model?

wraith ferry
#

So the template that i used had arms and stuff

#

So for this i just made them transparent for now

#

It works with them

#

But for some reason it doesnt work when the script inserts the players own hand

#

Like the pre made view model parts work, they follow the camera, but when the players hand is inserted by the script, it doesnt follow the camera for some reaso

wicked panther
#

yea weird

#

I grabbed a random viewmodel

#

and

#

same thing happens

#

imma try to fix it somehow

wraith ferry
#

Yeah

#

I've also tried making a motor6d or a weld constraint between the camera part and the hand but that just seems to bug it out

wicked panther
devout rootBOT
#

studio** You are now Level 17! **studio

wicked panther
#

I did it this way

#

so on the top is the original tool, on the bottom (Which follows the cam) is the pre-made model

wraith ferry
#

Yeah but i need to get the players hand to follow the cam

wicked panther
#

with the pre-model its easy

#

but idk how to make it so the actual hand follows

#

cuz player will prob have different avatar

wraith ferry
#

Yeah, its easy to make the pre made model follow

#

When i insert the players hand into the viewmodel though, it just doesnt follow the cam and i cant see why, i cant see any difference between the hand and the pre made model...

#

I dont really know what makes objects follow the camera in the script, cause i got it from a template

wicked panther
#

I made it work

#

almost

wicked panther
#

and the hand also has one, but its attached to the main bodu

#

*body

#

which is in this default position

#

idk how to fix it

#

tbh

#

local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local uis = game:GetService("UserInputService")

local ViewModel

local equipped = false

tool.Equipped:Connect(function()
equipped = true
game.ReplicatedStorage.ViewModel:Clone().Parent = Camera
for i, v in pairs(character:GetChildren()) do
if v.Name == "RightHand" then
local part = v:Clone()
part.Parent = Camera.ViewModel.Camera
part.Position = game.ReplicatedStorage.ViewModel.PosPart.Position
for _, child in pairs(part:GetChildren()) do
child:Destroy()
end

        local motor6D = Instance.new("Motor6D")
        motor6D.Parent = part
        motor6D.Part0 = part
        motor6D.Part1 = game.ReplicatedStorage.ViewModel.PosPart
        part.Anchored = true
    end
end

end)

tool.Unequipped:Connect(function()
equipped = false
ViewModel = Camera.ViewModel
ViewModel:Destroy()
end)

RunService.RenderStepped:Connect(function()
if player.Character.Humanoid.Health <= 0 then
if Camera:FindFirstChild("ViewModel") ~= nil then
workspace.Camera.ViewModel:Destroy()
end
end

if equipped == true then
    if Camera:FindFirstChild("ViewModel") ~= nil then
        Camera.ViewModel:SetPrimaryPartCFrame(Camera.CFrame)
        for i, v in pairs(Camera.ViewModel:GetChildren()) do
            if v:IsA("BasePart") then
                v.CanCollide = false
            end
        end
    end
end

end)

code ^^

#

I could try but I gtg

#

cya!

wraith ferry
#

Oh thx, i was afk btw, but thats awesome, i think what i was doing wrong is i tried making a motor6d, but i didnt anchor it, which caused it to buig out a ton.

wraith ferry
#

Well whatever ill fix it another dayt

#

Cya

wraith ferry
#

Oh nice i got it working... ill just put this post as solved

plucky viper
#

can i see?

#

actually there's a way to do the hands of a player

#

you just need the animation of a player holding the gun

#

then for the viewmodel you just need to do head nad the torso

#

watch this

#

research about localtransparencymodifier

#

i wont send any code here. just figure it out by yourself.

wraith ferry
#

Yeah i know but if you wanna make one for the camera only

wraith ferry
#

Dang it now i have another problem