Changing the attachment position property doesn't work properly

Hi, I want to change a attachment position but changing it does something like this:


which is not what I want, heres my script:

--(this is a local script)
local weapon = Char:FindFirstChild("Weapon")
local Attachment1 = weapon.End

local HRP = Target:FindFirstChild("HumanoidRootPart")
Attachment1.Position = HRP.Position
--(this runs everytime when a zombie is near the Char instance)

and heres the hierachy of the Char(the rig that the beam’s Attachment1 is connected to)
Image
idk what’s wrong with my script, any help would be appreciated c:

1 Like

Attachment Positions work in local space, which means relative to the part its attached to.

You can possibly edit the WorldPosition though this may do unusual things if the character moves as it changes.

If that’s a beam you should set Attachment0 to the turret’s attachment, and Attachment1 to a zombie’s attachment (possibly the one inside its HumanoidRootPart) which should be set to position 0,0,0 so it’s positioned at the middle of the part

you can jest move the hand up
it works

Thanks for the reply bro, your solution is working really good but as you said that

so yes the beam is acting weirdly when the char orientation changes that’s the only bug now besides that its working really good and I have no idea how to fix it :sad:

I did tried that but that’s not working as I want because I want the beam and its attachment1 to tween between zombies but this solution doesn’t work as smoothly as want it to be.

I don’t understand what are you trying to say, can you please elaborate more?

Oh I see, you don’t want it to snap to the other zombies basically. Well, another solution I can offer is to use a small part with an attachment in it (which you’d use as Attachment1) and using PreRender/RenderStepped to lerp its position (lerping so it doesn’t just snap to the new position) to the target’s position

1 Like
--(this is a local script)
local weapon = Char:FindFirstChild("Weapon")
local Attachment1 = weapon.End

local HRP = Target:FindFirstChild("HumanoidRootPart")
Attachment1.WorldCFrame= HRP.CFrame --change


--Use WorldPosition or WorldCFrame
--Attachment1.WorldPosition = HRP.Position
--(this runs everytime when a zombie is near the Char instance)

@XXsAAd_bHAiXX

I did tried that solution but there’s a orientation bug along with this solution so this isn’t complete solution.

have you tried WorldPosition?

Attachment1.WorldPosition = HRP.Position

That shouldn’t change the orientation
@XXsAAd_bHAiXX

Yes, even after that the results are same like this:

it seems there is some kind of delay

maybe you could use something like coroutine or runtime service to reduce this delay

or

you could ask ChatGPT, by pasting the entire script) to see why the delay happens, while you wait for answers

1 Like

Yes, there is a delay between attacking enemies. I have put a cooldown between each attack to balance the game like every other td game does and this cooldown/delay is 1 sec.

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