For some reason. i cant find my 'Level' Int value. but it sometimes does find it and sometimes it cant

all i wanna do is just put the player’s int value which is in ‘leaderstats’ in a variable. now sometimes it does work good and there’s no problem. but sometimes it doesn’t work and i get this error:
ServerScriptService.LvlChange:3: attempt to index nil with 'Level’

i’ve tried to do 'leaderstats:FindFirstChild(“Level”) and that didnt work too. i mean it did but only sometimes!

does anyone know how to fix it?
the code is pretty dumb ignore it.
code:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local Level = leaderstats.Level
	local temp = Instance.new("IntValue", Level.Parent)
	temp.Name = "temp"
	temp.Value = Level.Value
	while true do
		wait()
		if temp.Value ~= Level.Value then
			local Char = player.Character
			local DigPart = Char:FindFirstChild("Dig") 
			local value = 10
			if DigPart then
				DigPart.Size += Vector3.new(0, 1, 1)
				print("changed")
			end
			temp.Value = Level.Value
			
		end
		

	end
end)

You Never cloned inside leaderstats the level instance it’s nil because Does not exist Do you have others script that clone Instance inside the leaderstats when player join?

You could also try this let me know if that is what you mean:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new('Folder',player)
	leaderstats.Name = 'leaderstats'
	local temp = Instance.new("IntValue",leaderstats )
	local Level = Instance.new("IntValue", leaderstats )
	Level.Name = 'Level'
	temp.Name = "temp"
	local Level = leaderstats.Level
	temp.Value = Level.Value
	while true do
		wait()
		if temp.Value ~= Level.Value then
			local Char = player.Character
			local DigPart = Char:FindFirstChild("Dig") 
			local value = 10
			if DigPart then
				DigPart.Size += Vector3.new(0, 1, 1)
				print("changed")
			end
			temp.Value = Level.Value

		end
	end
end)

Use WaitForChild() instead (char limit)

Hey there :wave:t4:,
Replace

FindFirstChild()

with

WaitForChild()

and add to the

while true do

also an “if not” or else end

so the script don’t stop working if it should fail, also set wait() to wait(0.25) or (0.5) because you don’t need it checking so fast.