I have fixed it:
local UIP = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local CollectionService = game:GetService("CollectionService")
local TS = game:GetService("TweenService")
local Trove = require(game.ReplicatedStorage.Modules.Trove).new()
local dragging = false
local midRotation = false
local movement = false
local defaultDistancefromPlr = 10
local distanceFromPlr = defaultDistancefromPlr
local reachDistance = 15
local rotationDegrees = 45
local moveIncrement = 1
local ThrowForce = 8
local plr = game.Players.LocalPlayer
plr.CharacterAdded:Wait()
local Character = plr.Character
local Torso:MeshPart = Character:WaitForChild("Torso")
local Head:MeshPart = Character:WaitForChild("Head")
local Mouse = plr:GetMouse()
local Camera = workspace.CurrentCamera
local Target:Part
local Aori:Attachment
local A0:Attachment
local RotX = 0
local RotY = 0
local function Cleanup()
if dragging then
Trove:Clean()
Mouse.TargetFilter = nil
if Target then
Target.CollisionGroup = "Default"
end
Target = nil
Aori = nil
RotY = 0
RotX = 0
distanceFromPlr = defaultDistancefromPlr
dragging = false
end
end
UIP.InputBegan:Connect(function(Input,inText)
if inText then return end
if Input.UserInputType == Enum.UserInputType.MouseButton1 and not dragging then
if table.find(CollectionService:GetTags(Mouse.Target),"Draggable") then
if (Mouse.Target.Position-Torso.Position).Magnitude <= reachDistance then
dragging = true
Target = Mouse.Target
Target.Anchored = false
Target.CollisionGroup = "Grabbed"
local x,y,z = Target.Orientation.X,Target.Orientation.Y,Target.Orientation.Z
A0 = Trove:Add(Instance.new("Attachment",Target))
A0.WorldPosition = Mouse.Hit.Position
local PBall:Part = Trove:Add(Instance.new("Part",Target))
PBall.TopSurface = Enum.SurfaceType.Smooth
PBall.BottomSurface = Enum.SurfaceType.Smooth
PBall.Size = Vector3.new(.25,.25,.25)
PBall.CanCollide = false
PBall.Color = Color3.new(1, 1, 1)
PBall.Material = Enum.Material.Neon
PBall.Shape = Enum.PartType.Ball
PBall.Name = "Epicenter"
PBall.Transparency = .5
Mouse.TargetFilter = Target
local Apos:Attachment = Trove:Add(Instance.new("Attachment",workspace.Terrain))
Aori = Trove:Add(Instance.new("Attachment",workspace.Terrain))
local AlignP:AlignPosition = Trove:Add(Instance.new("AlignPosition",Target))
AlignP.Attachment0 = A0
AlignP.Attachment1 = Apos
AlignP.Responsiveness = 25
local AlignO:AlignOrientation = Trove:Add(Instance.new("AlignOrientation",Target))
AlignO.Attachment0 = A0
AlignO.Attachment1 = Aori
AlignO.Responsiveness = 25
local MouseBall:Part = Trove:Add(Instance.new("Part",Target))
MouseBall.TopSurface = Enum.SurfaceType.Smooth
MouseBall.BottomSurface = Enum.SurfaceType.Smooth
MouseBall.Size = Vector3.new(.25,.25,.25)
MouseBall.CanCollide = false
MouseBall.Color = Color3.new(1, 1, 1)
MouseBall.Material = Enum.Material.Neon
MouseBall.Shape = Enum.PartType.Ball
MouseBall.Name = "Cursor"
MouseBall.Transparency = .5
local AMouse:Attachment = Trove:Add(Instance.new("Attachment",workspace.Terrain))
local Rope:Part = Trove:Add(Instance.new("Part",Target))
Rope.TopSurface = Enum.SurfaceType.Smooth
Rope.BottomSurface = Enum.SurfaceType.Smooth
Rope.Color = Color3.new(1, 1, 1)
Rope.CanCollide = false
Rope.Material = Enum.Material.Neon
Rope.Name = "Connection"
Rope.Transparency = .5
Trove:Connect(RunService.Heartbeat,function()
local X,Y,Z = Mouse.Hit.X,Mouse.Hit.Y,Mouse.Hit.Z
local CF1 = CFrame.new(Head.CFrame.Position,Vector3.new(X,Y,Z))
local CF2 = CF1 * CFrame.new(0, 0, -distanceFromPlr)
Apos.CFrame = CFrame.new(CF2.X, CF2.Y, CF2.Z)
--local CRX = game.Workspace.CurrentCamera.CFrame.Rotation.X
--local CRZ = game.Workspace.CurrentCamera.CFrame.Rotation.Z
Aori.Orientation = Vector3.new(x+RotX,y+RotY,z)
AMouse.CFrame = CFrame.new(CF2.X, CF2.Y, CF2.Z)
MouseBall.CFrame = AMouse.CFrame
local RopeSizeZ = (A0.WorldPosition-MouseBall.Position).Magnitude
local RopePos = CFrame.new(A0.WorldPosition,MouseBall.Position)
RopePos *= CFrame.new(0,0,-RopeSizeZ*.5)
Rope.CFrame = RopePos
Rope.Size = Vector3.new(.1,.1,RopeSizeZ)
PBall.Position = A0.WorldPosition
end)
end
end
else
if not Target or midRotation or not Aori then return end
if Input.KeyCode == Enum.KeyCode.R and dragging then
midRotation = true
local Rot = Aori.CFrame.Rotation
Aori.CFrame = CFrame.Angles(Rot.X,Rot.Y+rotationDegrees,Rot.Z)
RotY += rotationDegrees
midRotation = false
elseif Input.KeyCode == Enum.KeyCode.T and dragging then
midRotation = true
local Rot = Aori.CFrame.Rotation
Aori.CFrame = CFrame.Angles(Rot.X+rotationDegrees,Rot.Y,Rot.Z)
RotX += rotationDegrees
midRotation = false
elseif Input.KeyCode == Enum.KeyCode.F and dragging then
local dir = Mouse.Hit.LookVector
local power = ThrowForce*Target:GetMass()
Target.AssemblyLinearVelocity = dir*power
Cleanup()
elseif Input.KeyCode == Enum.KeyCode.Q and dragging then
movement = true
while movement do
task.wait(.05)
distanceFromPlr = math.clamp(distanceFromPlr-moveIncrement,5,reachDistance)
end
elseif Input.KeyCode == Enum.KeyCode.E and dragging then
movement = true
while movement do
task.wait(.05)
distanceFromPlr = math.clamp(distanceFromPlr+moveIncrement,5,reachDistance)
end
end
end
end)
UIP.InputEnded:Connect(function(Input,inText)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
if inText then return end
Cleanup()
elseif Input.KeyCode == Enum.KeyCode.Q or Input.KeyCode == Enum.KeyCode.E then
movement = false
end
end)