Trying to Place Attachment 7 Studs In Front of Player

Honestly to me it doesn’t make that much sense. You have the position and it’s a lot more efficient to just use .Position than fancy CFrames.

READ:
All it does is mess up your positioning. I would say try to set the parent before you set the world positon

Take a look back at the code I posted where it was working.

See the thing is since you parent it to your humanoid root part your also updating the position with renderstepped . . .

So? it doesnt matter, I could put it in a function and it would still raycast correctly and position correctly.

Show me this in action, I’d love to see

YES I GOT IT WORKING, finally
took me long enough

Please try it out, I do not have access to gyazo and I have to upload everything to youtube. If you would please read the documentation of how it works, as well as try setting the parent before you set the world position, i’m sure we would have a much easier time.

1 Like

Could I ask what your solution was?

I used your formula with the ray end position - the humrp position and the negative magnitude using worldcframe and it worked

1 Like

I don’t like to beg, but please mark a solution. I don’t want to have people scrolling through this hour long thread.

The thing is you didnt exactly get me my solution and plus the code up there used WorldPosition and stuff, so I dont think you deserve it

Im just playing with you dude, I’ll mark it as a solution but which one of your posts?

Just do the one with the code, you bout gave me a heart attack, sorry for taking so long.

LOL, no it’s awesome that you stuck around and helped me I really appreciate it :sweat_smile:

1 Like

Found this to work:

attachment.CFrame = CFrame.new(0, 0, -(humrp.Size.Z + offset))

Code I used to test:

local offset = 7 -- changeable
game.Players.PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(c)
		local humrp = c:WaitForChild("HumanoidRootPart")
		local humsize_half = humrp.Size/2		
		local attachment = Instance.new("Attachment")
		attachment.CFrame = CFrame.new(0, 0, -(humsize_half.Z + offset))
		attachment.Visible = true
		attachment.Parent = humrp
	end)
end)

Attachment7Studs.rbxl (17.9 KB)

You shouldn’t be using both rays and positioning with magnitude to be doing something as simple as what I did but if that is an acceptable solution then it’s fine I guess.

Wait, also one more thing could you explain how this works

local mag = (position - humrp.Position).Magnitude
attachment.WorldCFrame = (humrp.CFrame * CFrame.new(0,0,-mag))

I’m confused, what is position for, did he want it relative to a humanoidrootpart and an object??

EDIT to below reply @xurmx: Did you want it to not go through the wall this whole time? I misread and thought you only wanted it relative to a humanoidrootpart. If you did, you would just fire a ray then and set the attachment at the end position. Use the character as an ignore descendants instance.

Oh thanks for all that but, thats kind of ineffective because depending on where I am it might go through the wall if im not exactly 7 studs

So basically, it gets the hit position, and it measures the distance between the humanoid root part and the hit point. Then it pushes it forward that amount of distance from the HRP.

1 Like

Hidden’s solution actually used the ray end point which is way better and efficient and will always exactly make up for the distance between my player and the wall

1 Like

It’s not “better and efficient” per say but that I misread and didn’t know you wanted it to not go through the wall. You just shoot a ray with a certain distance you want. You just multiply it by a given range.

If your title was exactly as what you wanted, my solution was the best for that problem.