Adding Vector3 to CFrame of tool

I’m trying to make a little sword hitbox. though when I want to change the position of the hitbox with Vector3, it doesn’t move with the rotation of the CFrame

swordHitBox.CFrame = script.Parent.Handle.CFrame  + Vector3.new(2,0,0)

image
image
Does anyone know how I fix this? Thanks.

Are you using CFrame:ToWorldSpace or CFrame:ToObjectSpace?

3 Likes

I don’t have any idea what these are, ill send u all the code:

script.Parent.Activated:Connect(function()
	local swordHitBox = Instance.new("Part")

	swordHitBox.CanCollide = false
	swordHitBox.Anchored = true
	swordHitBox.Parent = script.Parent
	swordHitBox.CFrame = script.Parent.Handle.CFrame + Vector3.new(2,0,0)
	swordHitBox.Transparency = .7
	swordHitBox.BrickColor = BrickColor.Red()
	swordHitBox.Material = Enum.Material.SmoothPlastic
	swordHitBox.Size = Vector3.new(5, 0.5, 5.5)
	wait(.3)
	swordHitBox:Destroy()
end)
2 Likes

When you spin around does the hitbox stay oriented to the other Part but face the same world direction compared to how your player is facing?

You could just weld the hitbox to the sword as well. It’s probably much easier.

1 Like

Without the + Vector3.new(2,0,0) it does, but after adding it, it doesn’t so. I get why but just fixing it is hard.
I just tried welding it but that doesn’t really work…

1 Like

Hello, if you want to add a vector relative to a CFrame, you can do so easily by multiplying the CFrame by another CFrame value with a position value of the vector. Multiplying CFrame values transforms the left CFrame by the right CFrame. (in this case, move the previous CFrame along the vector)

swordHitBox.CFrame = script.Parent.Handle.CFrame*CFrame.new(2,0,0)

Hope this helps!

1 Like

Are you trying to make the hitbox go ahead of the part?

If so, you should be using :ToObjectSpace() instead of adding a vector3

Try something like this:

swordHitBox.CFrame = CFrame.new(script.Parent.Handle.Position+Vector3.new(2,0,0))
1 Like

if you do

swordHitBox.CFrame = script.Parent.Handle.CFrame * CFrame.new(2,0,0)

It will add 2 studs in the relative space of the Handle’s CFrame.
This is the exact same as going through :ToObjectSpace but with a prettier syntax. Just adding a vector to a CFrame will translate the object relative to world coordinates.

1 Like

So this one just moves me, not the hitbox that gets made

1 Like

this just makes me look at the X axis

1 Like

Same thing with dolphin, this moves me and not the hitbox

1 Like

Hi! Sorry for late reply, but i want to help.
I agree with @Scottifly, weld hitbox to the sword will be much easier and don’t need much scripting.

Can you please describe what exactly works wrong with weld?

When i tried welding it, it just teleported me to 0,0,0 for some reason

I’m not sure, but i think this because of swordHitBox.Anchored = true
Try to set it false

If this don’t work, can you please send here short video, describing issue?

Can u tell me which weld to use? i normally use WeldConstraint but i dont know the difference between them…

Describe it will a little hard, you just need to do some tests to learn how they works.

There’s three types of weld:
WeldConstraing - It doesn’t save position between parts if they moved with setting CFrame, but save if moved with forces.

Weld - It always save position between parts, but it need to manually set positions bettween part.

Motor6D - The same as Weld, but easier to set position. Generally used to animate something

I used Motor6D for test

Hello, I see! It sounds like you’re trying to set the position of a hitbox relative to a rotating object, but you’re running into issues where the hitbox isn’t following the rotation properly or is being moved incorrectly.

If you’re trying to attach the hitbox to an object (like a sword) and make sure it moves with the object, especially when you want it to be rotated correctly, here’s the approach you can use. I’ll assume you’re dealing with a humanoid or character movement with a “dolphin” or some other object moving around.

Here’s an updated solution, taking rotation and position into account:

Solution

Copiar código

swordHitBox.CFrame = script.Parent.Handle.CFrame * CFrame.new(2, 0, 0)

This should work if you’re rotating the sword handle, and you want to move the hitbox relative to the handle. However, if it’s causing the character to move or is not updating as expected, here are a few checks to consider:

  1. Check Anchoring: Ensure that the hitbox is anchored (or part of a model that’s anchored or follows the handle), especially if it’s supposed to remain static when not interacting with other parts. You can try to use .Anchored = true for parts, or set up constraints to keep it in place relative to the handle.
  2. Make Sure You Are Modifying the Right Object: Double-check that you’re modifying the CFrame of the hitbox and not accidentally applying changes to the model or character itself. The CFrame property of the hitbox needs to be set and updated in every frame to ensure it tracks the handle’s position and rotation correctly.
  3. Moving with Rotation: If your hitbox is not following the rotation correctly, ensure that the offset you apply is always relative to the handle’s current position and rotation. The multiplication approach should ensure this, but if there’s any parent-child relationship or a body part involved, consider whether the object’s properties are overriding it.

Example:

If you’re rotating the sword and you want the hitbox to stay in place relative to the sword’s handle (with rotation), you would use something like this:

Copiar código

swordHitBox.CFrame = script.Parent.Handle.CFrame * CFrame.new(2, 0, 0)

This line will keep the hitbox 2 studs away from the sword handle along the X-axis, considering the handle’s current rotation.

Final Notes:

If the issue is more about the character movement (like a dolphin model), and you want to make sure that only the hitbox follows the sword, you can also ensure that the hitbox has a BodyPosition or similar mechanism to keep its position correctly adjusted, but that depends on the context (like if the sword is attached to a moving character).

Let me know if this clears it up, or if you’re still seeing issues with the movement!

1 Like

This doesnt quite change anything sadly…
I’m trying to make the sword hitbox start at the handle of the sword, but instead the center of the swordHitBox is where the handle touches, so the hitbox goes through my body(see previous screenshots, if i still need to send a video lmk)

did u ask chatgpt? lol, if u have seen the previous replies to this post, this answer has been given 3 times and it doesnt work.