I have created a move tool that works alright, but when i start to duplicate parts, it can get messed up. I have looked at many resources to try and fix it, but nothing helped. Somtimes if i move the part after it is duped, it will set it’s position to the original part. here is an example:
here is my code too:
local mouse = game.Players.LocalPlayer:GetMouse()
local coolness
local uis = game:GetService("UserInputService")
local debounce = false
local dragevent = game:GetService("ReplicatedStorage"):WaitForChild("DragEvent")
uis.InputChanged:Connect(function(input)
if mouse.Target then
if mouse.Target.Name == "Player_Part" then
coolness = mouse.Target
script.SelectionBox.Adornee = mouse.Target
else
if mouse.Target.Name == "Player_Part" then
print("cool")
else
script.SelectionBox.Adornee = nil
end
end
else
script.SelectionBox.Adornee = nil
end
end)
mouse.Button1Down:Connect(function()
if mouse.Target then
if mouse.Target.Name == "Player_Part" then
script.Parent.Handles.Adornee = mouse.Target
game:GetService("ReplicatedStorage").Target.Value = mouse.Target
local Part = mouse.Target
local CF
local Increment = 1
script.Parent.Handles.MouseButton1Down:connect(function()
CF = Part.CFrame
end)
script.Parent.Handles.MouseDrag:Connect(function(id, distance)
local moving = script.Parent.Handles.Adornee
local axi = {
[Enum.NormalId.Right] = moving.CFrame.RightVector,
[Enum.NormalId.Left] = -moving.CFrame.RightVector,
[Enum.NormalId.Top] = moving.CFrame.UpVector,
[Enum.NormalId.Bottom] = -moving.CFrame.UpVector,
[Enum.NormalId.Front] = moving.CFrame.LookVector,
[Enum.NormalId.Back] = -moving.CFrame.LookVector,
}
moving.CFrame = CF + axi[id] * (math.floor(distance / Increment) * Increment)
dragevent:FireServer(moving.CFrame,moving)
if debounce == false then
debounce = true
script.Switch:Play()
wait(0.5)
debounce = false
end
end)
else
script.Parent.Handles.Adornee = nil
end
else
script.Parent.Handles.Adornee = nil
end
end)