Attempt to index nil with 'FindFirstChild'

Ive been trying to make a stun script but whenever I check if theres not a object named stun in the character the game freaks out,

local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Char = Player.Character

local count = 1

local ResetTime = 4
local LastClick

Tool.Activated:Connect(function()
	if Char:FindFirstChild("Stun") then
		return
	end	
	
	if count == 1 then
		count = 2
		
	elseif count == 2 then
		count = 3
		
	elseif count == 3 then
		count = 4
		
	elseif count == 4 then
		count = 5
		
	elseif count == 5 then
		count = 1
		
		
		
	end
end)

The issue is on

if Char:FindFirstChild("Stun") then
		return
	end	

1 Like

I think the problem is that the “Char” variable is nil at time time you indexed it so a better way to get the character would be to:

local Char = Player.Character or Player.CharacterAdded:Wait()
1 Like