How can I prevent this from happening?

Hey developers! I have been working on a game that has a tool that when you activate it clones the handle and position it on top of it. But this happens when I move:

How can I fix this? Here is my code (a server script):

local player

repeat wait()
	
until script.Parent.Parent.Changed

player = script.Parent.Parent.Parent

local num = 1

script.Parent.Activated:Connect(function()
	local handle = script.Parent.Handle:Clone()
	handle.Parent = script.Parent
	handle.Name = 'ClonedHandle'..num

	handle.Position = script.Parent:FindFirstChild('ClonedHandle'..num).Position + Vector3.new(0,(3 * num),0)
	
	local weld = Instance.new('WeldConstraint', script.Parent.Handle)
	weld.Part0 = script.Parent.Handle
	weld.Part1 = handle
	num = num + 1
end)

Thanks!

1 Like

You are creating it directly on top of each other globally and not directly over the normal. To fix this, you’ll need to multiply the part’s UpVector and add it to the previous position.

The UpVector can be found in the CFrame property.

3 Likes

It’s because you’re welding it to the handle.
Scrap the weld, and anchor the part and parent it to workspace.

1 Like

I did this but here is what happens:


Here is my code:

local player

repeat wait()
	
until script.Parent.Parent.Changed

player = script.Parent.Parent.Parent

local num = 1

script.Parent.Activated:Connect(function()
	local handle = script.Parent.Handle:Clone()
	handle.Parent = script.Parent
	handle.Name = 'ClonedHandle'..num

	handle.CFrame = script.Parent:FindFirstChild('ClonedHandle'..num).CFrame + (script.Parent:FindFirstChild('ClonedHandle'..num).CFrame.UpVector * (3* num))
	
	local weld = Instance.new('WeldConstraint', script.Parent.Handle)
	weld.Part0 = script.Parent.Handle
	weld.Part1 = handle
	num = num + 1
end)

But if I parent it to the workspace and anchor it it wont follow the player’s tool.

I thought that was your intention…?

1 Like

Perhaps it’s not the UpVector. Otherwise try negative RightVector or LookVector. I remind you that LookVector, RightVector and UpVector are just one stud away from the normal.

handle.CFrame = script.Parent:FindFirstChild('ClonedHandle'..num).CFrame + ((script.Parent:FindFirstChild('ClonedHandle'..num).CFrame.RightVector * 3) * num)

Although you choose to use the top part, you can use the first part as the one determining which direction it should create at without having an issue of it narrowly bending.

1 Like

try it first with normal tool and handle and when u make that u make what u want if u wnat click and duplicate make that lol

1 Like

I think the way I’m welding it is wrong (with the script you sent me):

just make it a nor mal tool with handle and later add what do you want

1 Like

it is a normal tool with a handle? what do you mean?

yes a normal tool with no scripts (handle) and later u make scripts