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)
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.
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)
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.
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.