You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
Homing attack when pressing Q. - What is the issue? Include screenshots / videos if possible!
Homing attack stops after 3-6 presses
- What solutions have you tried so far? Did you look for solutions on the Creator Hub?
Tried UIS JumpRequest and InputBegin, Also tried the humanoid Jumped event.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Homing attack stops after 3-6 presses.
Not really much else to say, Though I am using a BodyPosition (Yes, i am aware i should be using AlignPosition). I am also using a custom rig, Though that shouldn’t impact it.
Here is the code for the homing attack:
local maxdist = 35
local curdist = math.huge
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local hrp = char.HumanoidRootPart or char:WaitForChild("HumanoidRootPart")
local CAS = game:GetService("ContextActionService")
local UIS = game:GetService("UserInputService")
local hum = char:FindFirstChildOfClass("Humanoid")
local jumped = false
local function getdist()
local attackpart = nil
for i, attack in pairs(workspace.Homing:GetChildren()) do
local dist = (attack.Position - hrp.Position).Magnitude
if dist < curdist and dist < maxdist then
curdist = dist
attackpart = attack
end
end
if attackpart then
print(attackpart)
return attackpart
else
return
end
end
task.spawn(function()
while task.wait(0.3) do
hrp = char:FindFirstChild("HumanoidRootPart")
end
end)
local function HomingAttack(input)
if jumped then
return
else
if hum.FloorMaterial == Enum.Material.Air then
local attackpart = getdist()
if attackpart then
jumped = true
local bp = Instance.new("BodyPosition",hrp)
bp.Position = attackpart.Position
bp.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bp.P = 100000
if attackpart:GetAttribute("LetGo") == false then
bp.ReachedTarget:Wait()
bp:Destroy()
hum:ChangeState(Enum.HumanoidStateType.Jumping)
task.wait(0.2)
jumped = false
else
task.wait(0.2)
bp:Destroy()
hum:ChangeState(Enum.HumanoidStateType.Jumping)
hrp.Velocity = hrp.CFrame.LookVector * 70
task.wait(0.2)
jumped = false
end
end
end
end
end
CAS:BindAction("HomingAttack",function()
task.spawn(function() HomingAttack() end) end,false,Enum.KeyCode.Q)
----------------------------------------------------------------------------------------------