-
What do you want to achieve? a telekinesis script where the target moves with the player’s mouse.
-
What is the issue? When the player’s mouse is not hovering over the target the script works regularly but when the mouse is on the target the target starts moving towards the camera. here’s a gif of it happening:
https://gyazo.com/060341880ca23e1a1cbdc139cbb2fe15 -
What solutions have you tried so far? None as I don’t know how to go about it, I’m guessing it’s because the mouse senses the target’s character as a part and moves the character forward but I don’t know how to get it to stop.
here’s the local script that handles most of the script:
--LOCAL
local UserInput = game:GetService("UserInputService")
local Replicated = game:GetService("ReplicatedStorage")
local Run = game:GetService("RunService")
local Debris = game:GetService("Debris")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HRP = Character:WaitForChild("HumanoidRootPart")
local Mouse = Player:GetMouse()
local Remotes = Replicated:WaitForChild("AOUWanda")
local Fire = Remotes:WaitForChild("Telekinesis")
local HRP = Character:FindFirstChild("HumanoidRootPart")
local Debounce = false
local Connection = nil
--local AnimFire = script:WaitForChild("Animation")
--local AnimFirePlay = Humanoid:LoadAnimation(AnimFire)
UserInput.InputBegan:Connect(function(Key, Processed)
if Processed then
return
end
if Debounce then
return
end
if Key.KeyCode == Enum.KeyCode.C then
Debounce = true
Fire:FireServer("On", Mouse.Hit)
--AnimFirePlay:Play()
local BodyGyro = Instance.new("BodyGyro")
BodyGyro.MaxTorque = Vector3.new(500, 500, 500)
BodyGyro.P = 10^7
BodyGyro.D = 100
BodyGyro.Parent = HRP
local target = Mouse.Target.Parent
Fire.OnClientEvent:Connect(function()
Connection = Run.RenderStepped:Connect(function()
Run.RenderStepped:Wait()
local Direction = Vector3.new(Mouse.Hit.Position.X - HRP.Position.X, 0, Mouse.Hit.Position.Z - HRP.Position.Z)
BodyGyro.CFrame = CFrame.new(HRP.Position, HRP.Position + Direction)
if target:FindFirstChild("Humanoid") then
local range = math.min(30, (HRP.Position - Mouse.Hit.p).Magnitude)
local direction = (Mouse.Hit.p - HRP.Position).Unit -- Might be backwards, swap hrp & pos if they are
target.HumanoidRootPart.CFrame = CFrame.new(HRP.Position + direction * range)
end
end)
end)
task.wait(10)
Connection:Disconnect()
BodyGyro:Destroy()
Fire:FireServer("Off")
--AnimFirePlay:Stop()
task.wait(5)
Debounce = false
end
end)
all help would be greatly appreciated