Checkpoint Error

Error:
image
I am not sure what to do.

local Checkpoints = script.Parent

for i,v in pairs(Checkpoints:GetChildren())do
	if v:IsA("BasePart")then
		v.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid")then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				if player then
					if player.leaderstats.Checkpoints.Value < tonumber(v.Name)then
						player.leaderstats.Checkpoints.Value = tonumber(v.Name)
					end
				end
			end
		end)
	end
end

Try to use WaitForChild I guess.

You probably ned to wait for it to exist

local Checkpoints = script.Parent

for i,v in pairs(Checkpoints:GetChildren())do
	if v:IsA("BasePart")then
		v.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid")then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				local stats = player:WaitForChild("leaderstats")
				if player then
					if stats.Checkpoints.Value < tonumber(v.Name)then
						stats.Checkpoints.Value = tonumber(v.Name)
					end
				end
			end
		end)
	end
end

now it is in a loop

image

Are you sure that you have Folder called ‘leaderstats’ inside your Player Instance?

And it wont keep the person on that checkpoint.

Are you certain you inserted your leaderstats correctly?

I do not believe I have done this.

Where is your code that inserts the folder?

image
The script is in here,

No no I meant, the code that inserts the leaderstats thing

There is no script for leaderstats.

Then that’s probably why then, nothing inserts a leaderstats folder into your player instance, you need to do that

Although I presume it was your former script that you had issues with?

Honestly I don’t script, it is a tutorial.

Then that’s probably why, I recommed learning the basics of scripting before you start any project because you’ll not go anywhere just by tutorials, having a grasp of Luau is essential

1 Like

Thank you. I will look into that. :smiley:

1 Like