Help with fire ball script

this is the fireball script
it says Players.noxomos.Backpack.FireBall.FireBall:119: attempt to index nil with ‘Position’ - Client - FireBall:119

local uis = game:GetService(“UserInputService”)
local repStore = game:GetService(“ReplicatedStorage”)
local tweenServ = game:GetService(“TweenService”)
local Debr = game:GetService(“Debris”)
local clientcast = require(repStore:WaitForChild(“Attacks”).AttackModule.ClientCast)

local plr = game:GetService(“Players”).LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = char:FindFirstChild(“Humanoid”)
local hrp = char:FindFirstChild(“HumanoidRootPart”)

local remote = repStore:FindFirstChild(“Remotes”).Attacks.Fire.FireAttack
local Resources = repStore:FindFirstChild(“Attacks”).Magic.Fire
local anims = Resources.Animation
local fx = Resources.FX

local tool = script.Parent

debounce = false

local function Goto(origin, direction, caster)
local fireBall = fx.FireBall
print(“go to”)
fireBall.Parent = workspace.MagicAttacks
game.Debris:AddItem(fireBall, 1.2)
local tween = tweenServ:Create(caster, TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.InOut), {CFrame = direction})

local Caster = clientcast.new(fireBall, RaycastParams.new())

local debTable = {}--plr cooldown

Caster:SetOwner(plr)
-- Set owner of ClientCaster, who will be the one to calculate collisions.
clientcast.HumanoidCollided:Connect(function(RaycastResult, HitHumanoid)
	if debTable[HitHumanoid] then
		return
	end
	debTable[HitHumanoid] = true
	print('Ow!')
	fireBall.FireAttch.Fire.Enabled = false
	fireBall.FireAttch.WindExpolsion:Emit(100)
	task.wait(0.5)
	debTable[HitHumanoid] = false
end)
-- Start detecting collisions
Caster:Start()

end

tool.Equipped:Connect(function()
print(“Equip”)
end)

tool.Activated:Connect(function()
print(“Activated”)
end)

tool.Deactivated:Connect(function()
local origin = hrp.Position + Vector3.new(1.5,0,-5)
local direction = mouse.Hit
local part = Goto(origin, direction, nil)
print(“YESSSS”)
remote:FireServer(“RenderBall”, plr.Name, direction)

local Caster = clientcast.new(part, RaycastParams.new())

local debTable = {}--plr cooldown

Caster:SetOwner(plr)
clientcast:StartDebug()
-- Set owner of ClientCaster, who will be the one to calculate collisions.
clientcast.HumanoidCollided:Connect(function(RaycastResult, HitHumanoid)
	if debTable[HitHumanoid] then
		return
	end
	remote:FireServer("Hit", nil, nil,HitHumanoid.Parent.Name, direction)
	debTable[HitHumanoid] = true
	print('Ow!')
	task.wait(0.5)
	part:Destroy()
	debTable[HitHumanoid] = false
	tool.Deactivated:Disconnect()
end)
-- Start detecting collisions
Caster:Start()

end)

remote.OnClientEvent:Connect(function()

end)

Can you format your code? It looks the error line is:
local origin = hrp.Position + Vector3.new(1.5,0,-5)
You make the assignment:
local hrp = char:FindFirstChild(“HumanoidRootPart”)
But you don’t check that it actually found it, so hrp could be nil. You may want to do WaitForChild or reference the models’ PrimaryPart.

1 Like