Trying to detect when someone levels up

I would like to detect when a player levels up and was wondering if someone could help me.

local value = game.Players.LocalPlayer.leaderstats.Level
value.Changed:Connect(function()
game.Players.LocalPlayer.leaderstats2.SP.Value=game.Players.LocalPlayer.leaderstats2.SP.Value+1
end)

I’ve tried fixing it many times and could not get it to work, could you help?

code made by a user named Dolphin_worm

That script alone wouldn’t level a player’s level up because there isn’t another script that updates a player’s level, it only detects when the level changes.

I have an xp and leveling script if thats what your saying

Yes, you need to have another script that changes the player’s level the script I wrote only runs when another script changes the player’s level.

You need a remote event. Do this:

--Put this in a script in "StarterPlayer" ---> "StarterPlayerScript"
 local Remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local value = game.Players.LocalPlayer.leaderstats.Level
value.Changed:Connect(function()
	Remote:FireServer()
end)



--Put this in a script in the "ServerScriptService"
local Remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Remote.OnServerEvent:Connect(function(Player)
	
	Player.leaderstats2.SP.Value = Player.leaderstats2.SP.Value + 1
end)
2 Likes

Try using GetPropertyChangedSignal

value:GetPropertyChangedSignal("Value"):Connect(function()
    Player.leaderstats2.SP.Value += 1
end)

I also used the “+=” its basically like “value = value + 1”, but shorter, you can also do -= if you want to

Also use the method @Inc_X with mine combined

In the end it should look like:

-- Local script

local Remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")

value:GetPropertyChangedSignal("Value"):Connect(function()
	Remote:FireServer()
end)

-- Server Script

local Remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Remote.OnServerEvent:Connect(function(player)
	player.leaderstats2.SP.Value += 1
end)

Hope i helped!