Attempt to index nil with 'Character' (Obby Checkpoint help)

So i’m a little lost as to why this error is being spammed in the output, as it is working correctly but still spams the output with:

The print statement worked as well…

Here’s the code of this for loop:

for _,Checkpoint in pairs(Checkpoints:GetChildren()) do
	
	if Checkpoint:IsA("BasePart") then
		local Value = Instance.new("IntValue", Checkpoint)
		Value.Value = Checkpoint.Name
		
		Checkpoint.Touched:Connect(function(Hit)
			local Player

			local s, e = pcall(function()
				Player = Players:GetPlayerFromCharacter(Hit.Parent)
			end)
			
			if s then
				local Number = Checkpoint.Value.Value
				
				if Player.Character:FindFirstChildOfClass("Humanoid").Health > 0 and Player.leaderstats.Stage.Value < Number and Player.leaderstats.Stage.Value == Number - 1 then
					Player.leaderstats.Stage.Value = Number
					print('worked')
				end
				
			end
		end)
		
	end
	
end

Line 110 is where the troubles are. Why perhaps is this happening and how can I fix it?

What may be happening is that you are detecting the hit of an accessory handle that is not directly on the character

image

What you could do in this situation is make a guard clause to detect if the part’s parent is a character

if not Hit.Parent:FindFirstChild("Humanoid") then return end
1 Like

Life saver, didn’t even think of that. Thank you very much!

1 Like

You don’t care about s you care about Player. Do if player.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.