Part not positioned where expected

I’m trying to positioned a bullet to the position of my barrel in an FPS system. However, despite giving them the exact same position, the bullet is not where the barrel is. I think this is because of the relative positions of each object. How could I fix this issue?

Inside the barrel, put an attachment, position this attachment to where you want the bullet to be when it spawns in. Inside your script, set the bullets position to the attachments position, easy way to make it be where ever you want, and you can tweak it!

For some reason, this still doesn’t work.

Here’s my current code:

	local gunComponents = gunModel.GunComponents
	local Barrel = gunComponents.Barrel
	local BulletMarker: Attachment = Barrel.BulletMarker
	
	local Bullet = Instance.new("Part")
	Bullet.Size = Vector3.new(1,1,5)
	Bullet.Anchored = true
	Bullet.CanCollide = false
	Bullet.Color = Color3.new(219,239,0)
	Bullet.Material = Enum.Material.Neon
	Bullet.Name = "Bullet"
	Bullet.Parent = workspace
	
	Bullet.CFrame = BulletMarker.WorldCFrame

Here’s the explorer whilst in game:

image

Must be you then, I used your exact script, I changed this though:
OLD

local BulletMarker: Attachment = Barrel.BulletMarker

NEW

local BulletMarker = workspace.Baseplate.Attachment

I feel like it might have something to do with the Barrel being within multiple models. Could you replicate my situation and see if it still works?

Could you try setting the CFrame before you set the Parent? Also, could you send a picture?

Code:

local gunComponents = gunModel.GunComponents
local Barrel = gunComponents.Barrel
local BulletMarker: Attachment = Barrel.BulletMarker

local Bullet = Instance.new("Part")
Bullet.Size = Vector3.new(1,1,5)
Bullet.CFrame = BulletMarker.WorldCFrame
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.Color = Color3.new(219,239,0)
Bullet.Material = Enum.Material.Neon
Bullet.Name = "Bullet"
Bullet.Parent = workspace

I’ve just tried that, and for some reason it doesn’t work. Here’s what it looks like:

The barrel is the part furthest from the camera. You can barely see it, but it’s there. The bullet part is nowhere to be seen.

Since you already have a part called barrel that is literally the barrel, there is no need to make an attachment for the bullet’s position. you can instead use the barrel part as the cframe plus a bit of math to make it point forward. code as follows:

local gunComponents = gunModel:WaitForChild("GunComponents")
local Barrel = gunComponents:WaitForChild("Barrel")

-- if this is made on the client, you can use the camera as the forward rotation, but i am going to assume this is on the server and use the barrel's rotation instead. if this IS on the server, you need to ensure the barrel part exists so the server can index it correctly

local Bullet = Instance.new("Part")
Bullet.Size = Vector3.new(1,1,5)
Bullet.CFrame = Barrel.CFrame
-- you may need to multiply this by 90 or 180 degrees to the left/right depending on what direction the barrel is facing. use *CFrame.Angles(0,math.rad(90),0) if you need to do that
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.Color = Color3.new(219,239,0)
Bullet.Material = Enum.Material.Neon
Bullet.Name = "Bullet"
Bullet.Parent = workspace

i am assuming you are interpolating the bullet on the server, so making the bullet point forward is important for your code. if the bulelt is still nowhere to be seen, read the comment in my code.

Maybe you have to parent it inside the view model, since this is a view model the positions of the parts might be weird, and it isn’t a guarantee for it to even show up in the camera.

What do you mean by “it”. The bullet or the barrel?

I mean the bullet, maybe put it inside the view model.