Attachment must be parented to partinstance

Hello devforum,

I’m making a raycast gun, and i’ve already run into quite a problem,

Reading this post, I know why the error is happening, but if it’s the tool itself that is a model, how would you cast from the origin of the gun barrel?

my tool tree:

my code:

local function active() -- i figure there'd be more problems with my code, so I put a little extra for you, devforum
local attachment1 ="Attachment", workspace)	
attachment1.Parent = tool.Barrel -- this is the piece of erroneous code
local attachment2 ="Attachment", workspace)
attachment2.Parent = mouse.hit
local beam ="Beam", workspace)
beam.Attachment0 = attachment1
beam.Attachment1 = mouse.hit.p
beam.Enabled = true
local raycastResult = workspace:Raycast(tool.Barrel.Position, mouse.hit.p)
1 Like

You have to parent the attachment to the barrel without parenting it to workspace first


Always a pleasure to forget to tie your shoelaces :smile:

1 Like