How can I fix Nil?

How can I solve this problem so that the script would run?

23:10:58.394 ServerScriptService.Player.LeftClickScript:68: attempt to index nil with ‘FindFirstChild’

LeftClick ServerScript

local Debounce = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local Combo = 1


ReplicatedStorage.Events.LeftClick.OnServerEvent:Connect(function(Player)
	if Debounce[Player.UserId] ~=  "CD" then	


		local hum = Player.Character.Humanoid

	Debounce[Player.UserId] = "CD"

	local Character = Player.Character
	
	if Combo == 1 then
				local Animation = Instance.new("Animation")
		Animation.AnimationId = "rbxassetid://6202773635"
						local anim = hum:LoadAnimation(Animation)	
		anim:Play()
		wait()
		Combo = 2
	elseif Combo == 2 then
		
		local Animation = Instance.new("Animation")
		Animation.AnimationId = "rbxassetid://6202771352"
		local anim = hum:LoadAnimation(Animation)	
		anim:Play()
		wait()
		Combo = 1
end
local Region = Region3.new(Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-3).p -Vector3.new(2,2,2), Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-3).p + Vector3.new(2,2,2))
		local RTable = workspace:FindPartsInRegion3(Region, nil, 20)
		for i, v in pairs(RTable) do

		if v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild("HumanoidRootPart") and v.Parent:FindFirstChild('Deb') == nil and v.Parent ~= Character and v.Parent ~= nil then			
			local Deb = Instance.new("BoolValue", v.Parent)
			Deb.Name = "Deb"
			
							game.Debris:AddItem(Deb, 0.1)
			v.Parent.Humanoid:TakeDamage(5)
			wait()
			local bv = Instance.new("BodyVelocity", v.Parent.HumanoidRootPart)
			bv.MaxForce = Vector3.new(1e8,1e8,1e8)
			bv.Velocity = Character.HumanoidRootPart.CFrame.lookVector*	4

			local bc = Instance.new("BodyVelocity", Character.HumanoidRootPart)
			bc.MaxForce = Vector3.new(1e8,1e8,1e8)
			bc.Velocity = Character.HumanoidRootPart.CFrame.lookVector*2
			game.Debris:AddItem(bv, 0.2)
			game.Debris:AddItem(bc, 0.2)				
	end
end

	
		wait()
	Debounce[Player.UserId] = nil
end
end)

FireBall ServerScript

local FireballEvent = game.ReplicatedStorage.Events:WaitForChild('Fireballevent')
local OnCoolDown = {}
FireballEvent.OnServerEvent:Connect(function(plr)
	local FireBall = Instance.new("Part", game.ServerStorage.Models_Parts)
	FireBall.Shape = "Ball"
	FireBall.CanCollide = false
	FireBall.Name = "FireBall"
	FireBall.Anchored = false
	FireBall.Color = Color3.new(1, 1, 1)
	FireBall.Material = Enum.Material.ForceField
	FireBall.Size = Vector3.new(2,2,2)
	FireBall.Transparency = 0
	if OnCoolDown[plr.UserId] ~= "CoolDown" then
	local Char = plr.Character
		local FireballClone = FireBall:Clone()

	FireballClone.CFrame = Char.HumanoidRootPart.CFrame
	
	local BodyVelocity = Instance.new("BodyVelocity", FireballClone)
		BodyVelocity.MaxForce = Vector3.new(1e8,1e8,1e8)
		BodyVelocity.Velocity = (Char.HumanoidRootPart.CFrame.lookVector*15)
				FireballClone.Parent = workspace.FireBallFolder
		game.Debris:AddItem(BodyVelocity, 3)

		spawn(function()
			if FireballClone then
				wait(3)
				FireballClone:Destroy()
			end
		end)

		OnCoolDown[plr.UserId] = "CoolDown"
		
		local TouchConnect
		TouchConnect = FireballClone.Touched:Connect(function(hit)
			local Humanoid = hit.Parent:FindFirstChild("Humanoid")
			local HumanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
			if Humanoid and HumanoidRootPart and hit.Parent.Name ~= plr.Name then

			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 15
				if TouchConnect ~= nil then TouchConnect:Disconnect() end
												FireballClone.Position = hit.Parent.HumanoidRootPart.Position
				FireballClone.Anchored = true
								local tweenin = TweenInfo.new(0.5, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)
				local Prop = {
					Size = Vector3.new(10,10,10)
				}
				local tween = game:GetService("TweenService"):Create(FireballClone,tweenin, Prop)
				tween:Play()
				FireballClone.Color = Color3.new(1, 0.835294, 0)
				wait(0.5)
					FireballClone:Destroy()
		end
		end)

		wait(0.1)
		OnCoolDown[plr.UserId] = nil
		end
end)

Folder

I have tried to find what it is detecting which is FireBall
the parent which is v.Parent of the FireBall is equal to nil
But it does not work as intended.

2 Likes

local plr = game.Players.LocalPlayer

Why are you trying to index the Local Player in a Server Script? Those can only work in LocalScripts (Plus it sorta ruins the variables that you already have indexed as a plr/Player
You can also try replacing FindFirstChild for WaitForChild instead, sometimes scripts need a bit of time to find where the Instance could lie (Also add print statements as well, preferably in line 68)

I added print for v and it gave me FireBall

It happens when I hit Left click and the FireBall part which has touched the Dummy’s HumanoidRootPart disappear and gave me an error where v.Parent == nil but v is FireBall

Have you tried checking if the object is nil or not? It could be something else that is nil, Change your loop to

		for i, v in pairs(RTable) do
			if v ~= nil then
				if v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild("HumanoidRootPart") and v.Parent:FindFirstChild('Deb') == nil and v.Parent ~= Character and v.Parent ~= nil then			
					local Deb = Instance.new("BoolValue", v.Parent)
					Deb.Name = "Deb"

					game.Debris:AddItem(Deb, 0.1)
					v.Parent.Humanoid:TakeDamage(5)
					wait()
					local bv = Instance.new("BodyVelocity", v.Parent.HumanoidRootPart)
					bv.MaxForce = Vector3.new(1e8,1e8,1e8)
					bv.Velocity = Character.HumanoidRootPart.CFrame.lookVector*	4

					local bc = Instance.new("BodyVelocity", Character.HumanoidRootPart)
					bc.MaxForce = Vector3.new(1e8,1e8,1e8)
					bc.Velocity = Character.HumanoidRootPart.CFrame.lookVector*2
					game.Debris:AddItem(bv, 0.2)
					game.Debris:AddItem(bc, 0.2)				
				end
			end
		end```. Lmk if it works or not

It said that the v.Parent == nil but when i print v it gave me FireBall

never mind I fixed it by deactivating and reactivating the script

when it was set to nil which resets the process.