~= nil not works

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)
1 Like

This just means that arms doesn’t have a PrimaryPart, you’ll need to add one yourself.

Thought if we’re talking about a Humanoid here, PrimaryPart will only exist in the Character.

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

use arms:PivotTo(cam.CFrame * CFrame.new(0,-1,0)) instead, SetPrimaryPartCFrame() is deprecated and should not be used for new work,

and Some Information can be here

also The difference between is that it works on BaseParts and Models as they’re PVInstance

2 Likes

Sorry, can you please translate that into English?

This is also correct and I should have mentioned that earlier.

1 Like

Wait i sorry the translator broken the text

arms have a PrimaryPart, but when gun unequips the arms was destroying, this means arms is nil.
I added this

if arms ~= nil then

but this not works

and script trying to setPrimaryPartCFrame

Try just:

if arms then
-- code
end

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.

Can you send a Local File, so I can fix quicker instead of typing with my fingers?

Never mind, don’t put it, it’s solved.

1 Like

Wait, i just changed to arms:PivotTo(cam.CFrame * CFrame.new(0,-1,0)) and everything fixed lol.
Maybe because SetPrimaryPartCFrame() deprecated

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.