OK so look, this is a fireball function:
wait(1) local player = game.Players.LocalPlayer local Mouse = player:GetMouse() local humanoid = player.Character.Humanoid local s = humanoid:LoadAnimation(game.StarterPack.StarterPack.Animation) Player = script.Parent.Parent Character = Player.Character Mouse = Player:GetMouse() usable = true function onKeyDown(key) key = key:lower() if key == "f" and usable then usable = false s:Play() player.Character.Humanoid.WalkSpeed = 16 wait(.73) local x = Instance.new("Part") x.TopSurface = "Smooth" x.BottomSurface = "Smooth" x.Shape = "Ball" x.Transparency = .7 x.BrickColor = BrickColor.new("Bright red") x.Size = Vector3.new(10, 10, 10) local z = Instance.new("Fire") z.Parent = x z.Size = 12 z.Heat = 12 local explosion = Instance.new("Explosion") explosion.Parent = game.Workspace explosion.Position = x.Position local y = Instance.new("BodyVelocity") y.maxForce = Vector3.new(math.huge, math.huge, math.huge) y.velocity = Character.Torso.CFrame.lookVector*80 y.Parent = x x.Parent = game.Workspace x.CFrame = Character.Torso.CFrame*CFrame.new(0, 0, -12) wait(3.5) x:remove() wait(.6) usable = true end end Mouse.KeyDown:connect(onKeyDown)
I wanna add a OnTouched function so when this fireball touches a humanoid, it disappears and does damage to the humanoid. But idk how to put a function -- into a function. .-.
Well, you defined the part that the fireball is, so, just insert in an anonymous function for when it's touched:
wait(1) local player = game.Players.LocalPlayer local Mouse = player:GetMouse() local humanoid = player.Character.Humanoid local s = humanoid:LoadAnimation(game.StarterPack.StarterPack.Animation) Player = script.Parent.Parent Character = Player.Character Mouse = Player:GetMouse() usable = true function onKeyDown(key) key = key:lower() if key == "f" and usable then usable = false s:Play() player.Character.Humanoid.WalkSpeed = 16 wait(.73) local x = Instance.new("Part") x.TopSurface = "Smooth" x.BottomSurface = "Smooth" x.Shape = "Ball" x.Transparency = .7 x.BrickColor = BrickColor.new("Bright red") x.Size = Vector3.new(10, 10, 10) local z = Instance.new("Fire") z.Parent = x z.Size = 12 z.Heat = 12 local explosion = Instance.new("Explosion") explosion.Parent = game.Workspace explosion.Position = x.Position local y = Instance.new("BodyVelocity") y.maxForce = Vector3.new(math.huge, math.huge, math.huge) y.velocity = Character.Torso.CFrame.lookVector*80 y.Parent = x x.Parent = game.Workspace x.CFrame = Character.Torso.CFrame*CFrame.new(0, 0, -12) x.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then hit.Parent.Humanoid:TakeDamage(10) -- Replace with damage amount. if x then -- Just in case, to counter the event that the fireball gets deleted before this. x:Destroy() end end end) wait(3.5) x:remove() wait(.6) usable = true end end Mouse.KeyDown:connect(onKeyDown)