So i made this viewmodel and then i put it in the camera but i want the viewmodel to only appear when a tool is equipped. I know it has something to do with "Tool.Equipped:Connect(function()" but I dont know how to put it together.
Script:
local cam = workspace.CurrentCamera
local run = game:GetService("RunService")
local reps = game:GetService("ReplicatedStorage")
local model = reps:WaitForChild("VSS ViewModel"):Clone()
for i,v in pairs (model:GetChildren()) do
if v:IsA("BasePart") then
if v ~= model.PrimaryPart then
local weld = Instance.new("Weld")
weld.Part0 = model.PrimaryPart
weld.Part1 = v
weld.C0 = model.PrimaryPart.CFrame:inverse()
weld.C1 = v.CFrame:inverse()
weld.Name = v.Name
weld.Parent = model.PrimaryPart
end
end
end
model.Parent = cam
run.RenderStepped:connect(function()
model:SetPrimaryPartCFrame(cam.CFrame *CFrame.new(0,-1.5, 1.5)) -- This is the position goes by X,Y,Z format
end)

7 comments
Thanks!
I recommend disconnecting the event on unequiped.
i like this explanation however the viewmodel still isn't becoming visible when the tool is equipped. Whenever i delete the weld the script just stops working completely
Nevermind I fixed it by just keeping the weld. Again thanks for this explanation.
you are using "Local" not "local" and the :connect is deprecated. use :Connect.
You dont really need your weld script, its actually useless. I tested it. I forgot to add something to my script. Ill add it right now and fix it. Thanks.
You need to parent the gun to your camera, I forgot to add that line.