I’m trying to make viewmodel, and when the gun unequips viewmodel destroys, but the script print this in output
Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.
I know this because arms is nil, but I have this check in the script
local arms
-- here some functions and gun equip
script.Parent.Equipped:Connect(function()
arms = game.ReplicatedStorage.ViewModels.Guns["AK-74"]:Clone()
if arms ~= nil then -- this not work
run.RenderStepped:Connect(function()
arms:SetPrimaryPartCFrame(cam.CFrame * CFrame.new(0,-1,0))
end)
end
arms.Parent = cam
end)
-- here the tool unequips and "arms" destroying
script.Parent.Unequipped:Connect(function()
arms:Destroy()
end)
Its have PrimaryPart. I mean if i unequip the gun, output prints this Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this
This is because if will evaluate a condition and check if it is truthy of falsey, if arms are nil then it will stop executing that thread and move onto the next one.