Need working change color checkpoint button

script.Parent.PrimaryPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		if game.Players:FindFirstChild(hit.Parent.Name) then
			local Player = game.Players:FindFirstChild(hit.Parent.Name)
			local level = Player:WaitForChild('leaderstats'):WaitForChild('Level')
			if level.Value == script.Parent.Name - 1 then
				level.Value = script.Parent.Name
				
				script.Parent.Button.BrickColor = BrickColor.new("Bright green")
				script.Parent.Button.Star.Enabled = true
				wait(0.5)
				script.Parent.Button.BrickColor = BrickColor.new("Bright yellow")
				script.Parent.Button.Star.Enabled = false
				
			end
		end
	end
end)

Trying to change to working with Stage 1+ change.
When someone touch it do color effect.
This script using “level.Value”

Can someone help?
I tryed edit to work with my system used “player.leaderstats.Stage.Value”, but still not work.
Thanks.

2 Likes

Are you getting any errors?

Also is “level” a number value?

I’m referring to this part:

local level = Player:WaitForChild('leaderstats'):WaitForChild('Level')

I want to know if the variable “Level” is a number or int value since you’re doing:

if level.Value == script.Parent.Name - 1 then

Also, open output and tell me if you’re getting any error like this:

attempt to perform arithmetic (sub) on string and number

Can you change your current code to the following and tell me what you see in output:

script.Parent.PrimaryPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player then
			print("running")
			local level = Player:WaitForChild('leaderstats'):WaitForChild('Level')
			print("Found stat")
			print(level.ClassName)
			if level.Value == tonumber(script.Parent.Name) - 1 then
				print("I'm assuming the if statement above was the previous issue??")
				level.Value = script.Parent.Name
				
				script.Parent.Button.BrickColor = BrickColor.new("Bright green")
				script.Parent.Button.Star.Enabled = true
				wait(0.5)
				script.Parent.Button.BrickColor = BrickColor.new("Bright yellow")
				script.Parent.Button.Star.Enabled = false
				
			end
		end
	end
end)

Remove the “PrimaryPart” from the touch connection. So instead do this since I don’t think the scripts parent is a model with a primaryPart:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player then
			print("running")
			local level = Player:WaitForChild('leaderstats'):WaitForChild('Level')
			print("Found stat")
			print(level.ClassName)
			if level.Value == tonumber(script.Parent.Name) - 1 then
				print("I'm assuming the if statement above was the previous issue??")
				level.Value = script.Parent.Name
				
				script.Parent.Button.BrickColor = BrickColor.new("Bright green")
				script.Parent.Button.Star.Enabled = true
				wait(0.5)
				script.Parent.Button.BrickColor = BrickColor.new("Bright yellow")
				script.Parent.Button.Star.Enabled = false
				
			end
		end
	end
end)

Can you show the code thats creating the “level” leaderstat?

I don’t think this is the right script as neither are creating any values called “Stage” or “Level”. Do you have any type of leaderboard script or anything thats creating the leaderstats folder, as well as these values?

That’s not it either.

If you’re comfortable with it. Could you just send your current place here so I can take a look at it to see what might be the issue?

What code makes this “Level” value?