I want to make an npc that will shoot fireballs and follow the player. I want the fireball to be activated once the npc detects player. Can someone pls help me combine these script and tell me about any error that may occur. Im quite new actually????????????
Follow script - function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 100 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:findFirstChild("HumanoidRootPart") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end --wait(math.random(0,5)/10) while true do wait(0.5) local target = findNearestTorso(script.Parent.HumanoidRootPart.Position) _G.target = findNearestTorso(script.Parent.HumanoidRootPart.Position) if target ~= nil then script.Parent.Humanoid:MoveTo(target.Position, target)
end
end
Fireball script
while true do wait(0.5)
local ball = Instance.new("Part") -- CREATE FIREBALL
ball.Parent = script.Parent.HumanoidRootPart -- DEFINE PARENT
ball.BrickColor = BrickColor.new("Neon orange")
ball.Material = Enum.Material.Neon
ball.Anchored = false -- SO IT DOSENT FALL ON GROUND
ball.CanCollide = false -- TO MAKE IT SHOOT
ball.Shape = Enum.PartType.Ball -- MAKE THE FIRE A BALL
ball.Size = Vector3.new(5,5,5) --SIZE
ball.CFrame = script.Parent.HumanoidRootPart.CFrame * CFrame.new(0,0,-6) -- SET CFRAME
local x = script.ParticleEmitter:Clone()
x.Parent = ball -- ADD FIRE EFFECT
local bodyv = Instance.new("BodyVelocity") -- SETTING UP SPEED
bodyv.Parent = ball -- PARENT
bodyv.MaxForce = Vector3.new(math.huge,math.huge,math.huge) -- MAXSPEED
bodyv.Velocity = script.Parent.HumanoidRootPart.CFrame.LookVector * 150 -- STUDS/1 SEC
local damage = game.ReplicatedStorage.damage:Clone()
damage.Parent = ball -- ADDING DMG
wait(1) ball:destroy() -- TO DESTROY INSTANCES TO REDUCE SERVER LOAD end -- SELF EXPLANATORY end

1 comment
I want to make an npc that will shoot fireballs and follow the player. I want the fireball to be activated once the npc detects player. Can someone pls help me combine these script and tell me about any error that may occur. Im quite new actually???????????? Follow script - function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 100 local temp = nil lo