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.
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)
First of all, delete that weld thing. Its useless (if you want the weapon to appear on your screen).
Now, you need a tool that will place the model to your camera, right? Easy.
You have the "Equipped" event that will fire when a player quipts his tool.
Lets go over some steps:
1) Make your tool. Insert a tool inside workspace and put a part inside it named "Handle". Make it transparent.
2) Take your script and put it inside the tool. Delete the weld thing because its pretty much useless.
3) Simply add "Equipped" event.
local tool = script.Parent tool.Equipped:Connect(function() end)
4) You need to add the "RenderStepped" inside the equipped event. Like this:
gun.Parent = cam tool.Equipped:Connect(function() run.RenderStepped:connect(function() model:SetPrimaryPartCFrame(cam.CFrame * CFrame.new(0,-1.5, 1.5)) end) end)
I am creating an FPS game too. Trust me, I gained a lot of knowledge ever since I started playing with this whole thing. If you want you can message me on ROBLOX and I will help you. Since I think we both have the same goal I guess.