Updating Leaderstats from Workspace script

Hi,

I am trying to update a player’s leaderstats from a Workspace script below, I am getting the player from the part the player touched.

it does not error but the leaderstats do not get updated what am I doing wrong?

local player = game.Players:GetPlayerFromCharacter(part.Parent)
local leaderstats = player.leaderstats
local PlayerCheckPoint = leaderstats and leaderstats:FindFirstChild(“CheckPoint”).Value
local CurrentCheckPoint = script.Parent.Parent.CheckPoint.Value

	if PlayerCheckPoint < CurrentCheckPoint then
		
		PlayerCheckPoint = PlayerCheckPoint + 1

            end if

you’re defining PlayerCheckPoint as leaderstats and leaderstats:FindFirstChild(“CheckPoint”).Value so you’re doing leaderstats and leaderstats:FindFirstChild(“CheckPoint”).Value += 1. You can’t increase an Instance and defining variables with .Value is not recommend (i think)

When you define PlayerCheckPoint as the CheckPoint.Value you’re not creating a reference to the CheckPoint.Value that you can update, you’re just copying over the current value of the CheckPoint. To update the leaderstat you need to manually update as leaderstats.CheckPoint.Value = PlayerCheckPoint + 1 or something like that.