Really annoying position error (Yes sorry for posting twice today)

So I have this really annoying position bug in my script that is constantly rendering position as nil

BeginnerBagClone.PrimaryPart.Position = script.Parent.Parent.Position

Its stumped me for a while because I thought it was gonna be an easy fix
adwas

Can you provide the rest of the script?

Yep here ya go

script.Parent.Triggered:Connect(function(Clicked)
	print("PLAYER INTERACTED")
	if Clicked.leaderstats.BagType.Value == "BeginnerBag" then
		print("BAG TYPE IS BEGINNER BAG")
		local BeginnerBag = game.Workspace.BeginnerTelescopeStuff.BeginnerBagsFolder.BeginnerBagClosed
		local BeginnerBagClone = BeginnerBag:Clone()
		
		BeginnerBagClone.PrimaryPart.Position = script.Parent.Parent.Position --Error is here
	else
		warn("NO BAG TYPE")
		return
	end
end)

PrimaryPart.Position is rendering as nil, likely because the PrimaryPart property of BeginnerBagClone might not be set.

You should also ensure script.Parent.Parent has a valid position. If it’s a model or another object without a Position property, it will result in nil.

I’ve modified your script to include checks to ensure the PrimaryPart is set and the parent object has a valid Position property. Let me know what the output is?

script.Parent.Triggered:Connect(function(Clicked)
	print("PLAYER INTERACTED")
	if Clicked.leaderstats.BagType.Value == "BeginnerBag" then
		print("BAG TYPE IS BEGINNER BAG")
		local BeginnerBag = game.Workspace.BeginnerTelescopeStuff.BeginnerBagsFolder.BeginnerBagClosed
		local BeginnerBagClone = BeginnerBag:Clone()
		
		-- Check if PrimaryPart is set
		if not BeginnerBagClone.PrimaryPart then
			warn("PrimaryPart is not set for BeginnerBagClone")
			return
		end
		
		-- Check if Parent has a Position property
		if not script.Parent.Parent.Position then
			warn("script.Parent.Parent does not have a valid Position property")
			return
		end

		BeginnerBagClone.PrimaryPart.Position = script.Parent.Parent.Position
	else
		warn("NO BAG TYPE")
		return
	end
end)

das

You need to set a Primary Part for the BeginnerBagClone model.

Go to the properties tab, select PrimaryPart and set it to something in your model.

Error is gone however now its not teleporting

Still did not work does it have to be unanchored or something…?

My bad. Try BeginnerBagClone:SetPrimaryPartCFrame(script.Parent.Parent.CFrame)

Still the bag did not teleport
Ill send you a video real quick
robloxapp-20240706-1545426.wmv (598.7 KB)

Would you be comfortable sending the place file ?

I can send a copy if needed

Text Limit

Save the place file to your Desktop and drag/drop to upload it here. Or you can upload it by sending me a message on the forum privately.

You forgot to set the clone’s parent to workspace. Try this:

script.Parent.Triggered:Connect(function(Clicked)
	print("PLAYER INTERACTED")
	if Clicked.leaderstats.BagType.Value == "BeginnerBag" then
		print("BAG TYPE IS BEGINNER BAG")
		local BeginnerBag = game.Workspace.BeginnerTelescopeStuff.BeginnerBagsFolder.BeginnerBagClosed
		local BeginnerBagClone = BeginnerBag:Clone()
		BeginnerBagClone.Parent = workspace -- You need to parent the clone to workspace.

		-- Check if PrimaryPart is set
		if not BeginnerBagClone.PrimaryPart then
			warn("PrimaryPart is not set for BeginnerBagClone")
			return
		end

		-- Check if Parent has a Position property
		if not script.Parent.Parent.Position then
			warn("script.Parent.Parent does not have a valid Position property")
			return
		end

		BeginnerBagClone:SetPrimaryPartCFrame(script.Parent.Parent.CFrame)
	else
		warn("NO BAG TYPE")
		return
	end
end)
1 Like

Thanks! Works now

Text Limit

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