Prestige system won't work

I know this probably a dumb question to ask ,but I’ve only been scripting for a few months. I’m trying to make an obby prestige system that only works if the player is on a specific stage.
For some reason the prestige won’t add to the leaderstats and the stage number won’t reset when I set it to trigger at a specific number. Here’s the prestige script

local debounce = 0 
local player = game.Players.LocalPlayer

function onTouched(hit)
	
	if debounce == 0 then 
		debounce = 1 
		
		local check = hit.Parent:FindFirstChild("Humanoid") 
		
		if check ~= nil then
			
			local user = game.Players:GetPlayerFromCharacter(hit.Parent)
			local stats = user:findFirstChild("leaderstats") 
			
			if player.stats:WaitForChild("Stage") == 2 then
				local Prestige = stats:findFirstChild("Prestige") 
				Prestige.Value  = Prestige.Value +1 
				wait(2) 
			end
			
		end
		
		debounce = 0 
	end
	
end

script.Parent.Touched:connect(onTouched)

The script seems to break down at the third ‘if then’ because when I set it to ‘stats ~= nil’ it works but exploiters can fly to the end and get the prestige without doing the obby.

if player.stats:WaitForChild("Stage") == 2 then

Thank you for your time…

Question. Is this a local script or regular script?

Edit: If it is a regular script, you can’t use game.Players.LocalPlayer. Y

It’s a regular script inside of a part

You can’t use game.Players.LocalPlayer then

Oh ok, what would I use to get the player?

Your user variable is actually already getting the player.

On this part, you are comparing (supposingly) an IntValue to an integer. You should be using

if user.stats:WaitForChild("Stage").Value == 2 then

since it returns its value. Without .Value, you are comparing the item’s .Name

EDIT: player.stats should be user.stats, since you cant access a LocalPlayer through a server side script

1 Like

local debounce = 0

function onTouched(hit)

if debounce == 0 then 
	debounce = 1 
	
	local check = hit.Parent:FindFirstChild("Humanoid") 
	
	if check ~= nil then
		
		local user = game.Players:GetPlayerFromCharacter(hit.Parent)
		local stats = user:findFirstChild("leaderstats") 
		
		if user.stats:WaitForChild("Stage") == 2 then
			local Prestige = stats:findFirstChild("Prestige") 
			Prestige.Value  = Prestige.Value +1 
			wait(2) 
		end
		
	end
	
	debounce = 0 

Since it seems the only error is trying to access the player as a LocalPlayer, I got rid of that and got the player object by referencing the user variable, which should be equal to the player.

I replaced player with user and tried both removing the ‘.Value’
and user.stats.Stage.Value == 2 yet it still doesn’t work.

you should add .Value, not remove it

Oh sorry about that. It seems to work now thanks.