Boss Fight Script Help

Hello fellow devforum users! I have recently encountered a game breaking bug preventing my boss fight from working. If you see anything wrong with this code please let me know what it is. All help is appreciated!

local fireball = game.ReplicatedStorage.AbilityItems.FireBall
local lava = fireball.Parent.Lava
local target = lava.Parent.Circle
local plrs = game:GetService("Players")
local plr = plrs:GetPlayers()[1] or plrs.PlayerAdded:Wait()
local db = false

local function FireBallRain()
	if db == false then
		db = true
		local new = fireball:Clone()
		local new2 = target:Clone()
		new2.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0, -2, 0)
		task.wait(.7)
		new.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0, 15, 0)
		new.Anchored = false
		wait(2)
		new2:Destroy()
		wait(5)
		new:Destroy()
		task.wait(1)
		db = false
	end
end

for i=1, 10 do
	FireBallRain()
end

Thanks in advanced.

the output says something along the lines of “Attempt to index nil with HumanoidRootPart”

do FireBallRain(player)in for 1 = 1,10 and do FireBallRain(plr) for the function

Hello, seems like plr.Character is returning nil.
try this instead:
local fireball = game.ReplicatedStorage.AbilityItems.FireBall
local lava = fireball.Parent.Lava
local target = lava.Parent.Circle
local plrs = game:GetService(“Players”)
local plr = plrs:GetPlayers()[1] or plrs.PlayerAdded:Wait()
local char = plr.Character or player.CharacterAdded:Wait()
local db = false
local function FireBallRain()
if db == false then
db = true
local new = fireball:Clone()
local new2 = target:Clone()
new2.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(0, -2, 0)
task.wait(.7)
new.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(0, 15, 0)
new.Anchored = false
wait(2)
new2:Destroy()
wait(5)
new:Destroy()
task.wait(1)
db = false
end
end
i added in a line that waits for the player’s character to load in. If it still doesn’t work, it would be helpful if you could provide more details about what is wrong

wait no i meant plr for both FireBallRain like this FireBallRain(plr)

Do you mean something similar to this:

for i=1, 10 do
	FireBallRain(plr)
end
local function FireBallRain(plr)

yes try that and tell me if it works

Attempt to index nil with ‘Character’

This is a server script inside ServerScriptService if that helps.

i fixed your script. please try the fixed version i sent.

Sure thing! I’ll do it whenever I can and share the results. Thanks for the help!

Not sure I follow what the script is looking to do here… Maybe try a different way to get the information needed.

players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local root = character:WaitForChild("HumanoidRootPart")