My fireball script has a ton of problems and idk why

So im making this fireball script and it has a ton of problems

  1. Goes super fast if u spam

  2. Messy code and hard to read

  3. Doesn’t work when one of the bullets get destroyed (FIXED)

  4. Just looks really wonky

Heres the code do not read if you are allergic to bad code

--Server
local Tool = game.StarterPack:WaitForChild("B a l l")
local Handle = Tool:WaitForChild("Handle")
local Yeet = game.ReplicatedStorage.Fireball:WaitForChild("Yeet")
local Players = game:GetService("Players")
local Bullet = game.ReplicatedStorage.Fireball:WaitForChild("Bullet")
local debounce = true
local count = 100


function shoot(root,name)
--parent
Bullet.Parent = workspace
	--positioning
	Bullet.Orientation = root.Character.HumanoidRootPart.Orientation
	Bullet.CFrame = root.Character.HumanoidRootPart.CFrame
	--offset so u dont die
			Bullet.CFrame = Bullet.CFrame + Bullet.CFrame.LookVector * 10	
	-- properties
	Bullet.Anchored = false
	--move
while count > 1 do
		Bullet.CFrame = Bullet.CFrame + Bullet.CFrame.LookVector
		wait(0.1)
	end
	count = 100
	Bullet:Destroy()
end	



function damage(part)
	if part.Parent.Humanoid then
		wait(0.1)
		part.Parent.Humanoid.Health -= 10
		part.Parent.Humanoid.Jump = true
		part.Parent.Humanoid.Sit = true
		Bullet:Destroy()
		Handle.Parent = Tool
	end
end

--connect
Bullet.Touched:Connect(damage)
Yeet.OnServerEvent:Connect(shoot)
--Client
local Handle = script.Parent:WaitForChild("Handle")
local Tool = script.Parent
local Yeet = game.ReplicatedStorage.Fireball:WaitForChild("Yeet")
local Players = game:GetService("Players")

Tool.Activated:Connect(function()
	print("clicked")
	Yeet:FireServer(Players.LocalPlayer.Character,Players.LocalPlayer.Name)
end)

while wait() do
	Handle.Fire.Size = math.random (2.5,7.5)
end

Sorry for burning ur eyes

while count > 1 do
Bullet.CFrame = Bullet.CFrame + Bullet.CFrame.LookVector
wait(0.1)
end
count = 100
Bullet:Destroy()
end

You can use BodyMovers to do this instead of looping.

I tried with body movers but it always pointed toward the vector instead of infront of the character

Use CFrame to place towards player, after that use BodyMovers.

Tried but it always goes to a direction I don’t want it to like it always goes front no matter where ur standing

	Bullet.Orientation = root.Character.HumanoidRootPart.Orientation

then

	bodymover.Force = Vector3.new(0,0,500)

CFrame would be better.

local offset = Vector3.new(0, 0, 0) -- Offset you want
Bullet.CFrame = root.Character.HumanoidRootPart.CFrame * CFrame.new(offset)
1 Like

And try to change Force to Vector3.new(1, 1, 1)
Edited : This will make it go to both 3 directions.

1 Like

This works

This didn’t work it just went diagonal not the way I was facing