Hey there! I am making a script where you can to the enemy the mouse is pointing at. The only problem however, is that you would still be able to dash, even when the mouse is off the enemy or you moved the specified 40 studs away from the enemy
Here is that script:
--[[ Values ]]-- local canDash = true local looping = true --[[ Math ]]-- --[[ Services ]]-- local runService = game:GetService("RunService") local userInputService = game:GetService("UserInputService") --[[ Player Variables ]]-- local player = game:GetService("Players").LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local mouse = player:GetMouse() --[[ Variables ]]-- local humanoidRootPart = character:WaitForChild("HumanoidRootPart") --[[ Functions ]]-- --[[ Script ]]-- runService.RenderStepped:Connect(function() local mTarget = mouse.Target local humanoid = mTarget.Parent:FindFirstChild("Humanoid") local targetHumanoidRootPart = mTarget.Parent:FindFirstChild("HumanoidRootPart") if humanoid then if not targetHumanoidRootPart then return end local distance = (targetHumanoidRootPart.Position - humanoidRootPart.Position).Magnitude if mTarget.Parent.Name == player.Name then return end if (distance > 40) then canDash = false return end userInputService.InputBegan:Connect(function(input, gameProcessed) if input.KeyCode == Enum.KeyCode.E then print("E has been pressed") if canDash then print("Dashed") canDash = false humanoidRootPart.CFrame = targetHumanoidRootPart.CFrame wait(.3) canDash = true end end end) end end)
Any help is appreciated!