Alright, fellas, I got an issue.
Right now what I am trying to do is that I want an NPC to fire a part or “Fireball” at the nearest player position. So far I got the fireball to spawn and shoot.
But it won’t go in the direction of the player, it’ll just shoot at the ground from its position which is the NPC’s right hand.
I don’t want a homing missile either. Just fire it at the nearest player’s exact location.
My big dumb brain can’t seem to figure this issue out for like a day. Never was good at making projectiles.
local Fired = true
spawn(function()
while true do
wait()
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
wait(5)
local fireball = game.ReplicatedStorage.Fireball:Clone()
fireball.CFrame = target.CFrame
fireball.Position = script.Parent.RightHand.Position
local bp = Instance.new("BodyPosition")
bp.MaxForce = Vector3.new(math.max,math.max,math.max)
bp.Position = Vector3.new(target.Position.X,target.Position.Y,target.Position.Z)
bp.Parent = fireball
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.max,math.max,math.max)
bv.Velocity = Vector3.new(target.Position.X,target.Position.Y,target.Position.Z)
bv.Parent = fireball
fireball.Anchored = false
fireball.CanCollide = false
fireball.Transparency = 0
fireball.Fly:Play()
fireball.Parent = game.Workspace
game.Debris:AddItem(fireball,50)
wait(1)
Fired = true
fireball.Touched:connect(function(hit)
if not Fired then return end
Fired = false
local hum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
local zombie = hit.Parent:FindFirstChild("Zombie") or hit.Parent.Parent:FindFirstChild("Zombie")
if hum then
hum:TakeDamage(25)
fireball.Hit:Play()
fireball.Fly:Stop()
fireball.BodyVelocity:Destroy()
fireball.Anchored=true
wait(fireball.Hit.TimeLength)
fireball:Destroy()
elseif zombie then
zombie:TakeDamage(25)
fireball.Hit:Play()
fireball.Fly:Stop()
fireball.BodyVelocity:Destroy()
fireball.Anchored=true
wait(fireball.Hit.TimeLength)
fireball:Destroy()
else
fireball.Hit:Play()
fireball.Fly:Stop()
fireball.BodyVelocity:Destroy()
fireball.Anchored=true
wait(fireball.Hit.TimeLength)
fireball:Destroy()
end
wait(1)
Fired= true
end)
end
end
end)
Thanks.