I'm following a tutorial for a first person viewmodel. It doesnt work and repeatedly returns the following error when I run it:
Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this. - Client - Framework - Client:38
I've already set the Primary part to the model in a replicated storage folder.
Code:
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:wait() local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local camera = game.Workspace.CurrentCamera local framework = { inventory = { "FNC"; "HiPower"; "Knife"; "M26"; }; module = nil; viewmodel = nil; } function loadSlot(Item) local viewmodelFolder = game.ReplicatedStorage.Viewmodels local moduleFolder = game.ReplicatedStorage.Modules if moduleFolder:FindFirstChild(Item) then framework.module = require(moduleFolder:FindFirstChild(Item)) if viewmodelFolder:FindFirstChild(Item) then framework.viewmodel = viewmodelFolder:FindFirstChild(Item):Clone() framework.viewmodel.Parent = camera end end end RunService.RenderStepped:Connect(function() for i, v in pairs(camera:GetChildren()) do if v:IsA("Model") then v:SetPrimaryPartCFrame(camera.CFrame) end end end) loadSlot(framework.inventory[1])
Try this
local player = game.Players.LocalPlayer local character = player.Character or player:WaitForChild("Character") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local camera = game.Workspace.CurrentCamera local framework = { inventory = { "FNC"; "HiPower"; "Knife"; "M26"; }; module = nil; viewmodel = nil; } function loadSlot(Item) local viewmodelFolder = game.ReplicatedStorage:WaitForChild("Viewmodels") local moduleFolder = game.ReplicatedStorage:WaitForChild("Modules") if moduleFolder:FindFirstChild(Item) then framework.module = require(moduleFolder:FindFirstChild(Item)) if viewmodelFolder:FindFirstChild(Item) then framework.viewmodel = viewmodelFolder:FindFirstChild(Item):Clone() framework.viewmodel.Parent = camera end end end RunService.RenderStepped:Connect(function() for i, v in pairs(camera:GetChildren()) do if v:IsA("Model") then v:SetPrimaryPartCFrame(camera.CFrame) end end end) loadSlot(framework.inventory[1])