How to: Find part inside an Object value part

		local guns = script.Guns:GetChildren() --- GUNS FOLDER
		local Holders = GunSystemFolder.GunHolders:GetChildren()  --- HOLDER FOLDER
		print(guns)
		print(Holders)
		for i,H in pairs(Holders) do
			if H.GunAssigned.Value then -- IF THE VALUE EXIST
				local Gun = H.GunAssigned.Value  --- THE OBJECT VALUE
				local clone = Gun:Clone()  -- CLONE THE PART IN THE OBJECT VALUE
				clone.Parent =  GunSystemFolder.Guns  -- ASSIGN PARENT TO THE CLONED PART
				print(clone.PrimaryPart.Name) -- PRINT THE NAME OF A PART INSIDE THE CLONED PART
-----------------------THE PROBLEM^ 
				--clone.PrimaryPart.CFrame = CFrame.new(H.Position)
			end
			
		end

Error:

Players.OriginalEngineer.PlayerGui.GunShop.GunShopHandler:81: attempt to index nil with 'Name'  -  Client - GunShopHandler:81

I am trying to access a part of a cloned part of an Object Value.

Well are you appending the ObjectValue’s value on the client? Just to get something outta the way

Does the clone exist? Check if the clone exists first.

If it does, check if the PrimaryPart needs to be assigned (by checking the gun model in the Explorer)

Well are you appending the ObjectValue’s value on the client?
YES

Does the clone exist? Check if the clone exists first.

Yes, I did print(Clone.Name)

If it does, check if the PrimaryPart needs to be assigned (by checking the gun model in the Explorer)
NVIDIA_Overlay_vWfjOHOgCR
The Primary Part is inside the clone.

1 Like

Ah I think i see the issue.

Models have a property called PrimaryPart, that’s why when you call Character.PrimaryPart, it returns the player’s HumanoidRootPart.

I assumed that the PrimaryPart you was referring to was set in the model.

In this case, you’ll have to set the PrimaryPart of the gun model to that part or you’ll have to change the part’s name

Why is it erroring? The script is assuming you’re talking about the property and it looks in the value of the property and finds nothing, nil

So the order is
local Object = H.GunAssigned.Value
local CloneOfObject = Object:Clone
And then when I try to access the name a part called PrimaryPart inside the ClonedOfObject it returns
attempt to index nil with 'Name'

Did you assign the PrimaryPart of the models to that part or did you change the name of the part?

No the PrimaryPart already exist inside the part

No no I mean like look in the gun models’ properties… you’ll see “PrimaryPart” click it and then click on the part “PrimaryPart”

Oh crap I didn’t know that property existed :skull: , I was trying to index the part but it was indexing the property :man_facepalming:

1 Like

Yeah in the AutoComplete it might’ve shown you two things.

1 Like

NVIDIA_Overlay_JxcgfxoN9D
Can you also help me with this?
I have clone.PrimaryPart.CFrame = CFrame.new(H.Position)
When it clones, the gun faces into weird positions, may I ask if there’s a way to set the new CFrame with it facing the correct direction?

1 Like

Uh mb for the a bit late response… H doesn’t have a CFrame property?

When creating a new Identity CFrame, the rotational component is gonna be well obviously (0, 0, 0) and since Position properties don’t contain rotations / rotation matrices that means that the rotation will not “transfer”

The CFrame of H contains the rotation matrix while the Position doesn’t.

And I doubt that this is a GUI object since you’re setting the CFrame of a Part to this position so it probably has a CFrame property

the guy in your other post has the right idea

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