Fireball script not working properly

  1. What do you want to achieve? a simple fireball ability

  2. What is the issue? the fireball doesn’t show properly and I take damage instead of the target

  3. What solutions have you tried so far? I’m pretty new to scripting and I followed a tutorial and modified it to my liking but I think I did something wrong.

ServerScript

local fireball = game:GetService("ServerStorage").Blast

local fireballSpeed = 100
local fireballLifetime = 5
local fireballDamage = 15

local cooldown = 1.5
local canshoot = true

script.Parent.Fire.OnServerEvent:Connect(function(player)
	if not canshoot then return end
	
	canshoot = false
	
	local root = player.Character.HumanoidRootPart
	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(1,1,1) * 30000
	bv.Velocity = root.CFrame.lookVector * fireballSpeed
	
	local fb = fireball:Clone()
	fb.Parent = game.Workspace
	fb.CFrame = root.CFrame
	bv.Parent = fb
	
	game.Debris:AddItem(fb,fireballLifetime)
	
	fb.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid.Health -= fireballDamage
			fb:Destroy()
		end
	end)
	
	wait(cooldown)
	canshoot = true
end)

any help is greatly appreciated

Make sure you add an if statement to make sure the hit part isn’t hitting any parts of your character model.

2 Likes

thank you so much, I hadn’t thought of that!