I want to make something once the player's value goes up by 1. I made a server script that does that. But, it is not working. Here is the script:
1 | wait( 2 ) |
2 |
3 | if game.Players.Player.leaderstats.Stage.Value + 1 then |
4 | print ( "value up" ) |
5 | end |
like I commented, use GetPropertyChangedSignal. im on phone rn so I cant test this but this is how it works.
1 | local stage = game.Players.LocalPlayer.leaderstats.Stage |
2 |
3 | stage:GetPropertyChangedSignal( "Value" ):Connect( function () |
4 | print ( "value changed" ) |
5 | end ) |
also, if this is a serverscript you need to get the specific Player. I think its better on a localscript anyway.
edit: you could also use this
1 | stage.Changed:Connect( function () |
2 | print ( "value changed" ) |
3 | end ) |
and this would check to see if any property at all, not just Value has changed. but a leaderstat only has Value.
Assuming this script is going in ServerScriptService. You wrote the script wrong. It is supposed to be LocalPlayer not Player.
1 | if game.Players.LocalPlayer.leaderstats.Stage.Value + 1 then |
2 | print ( "value up" ) |
3 | end |
I commonly use a connect to player system:
1 | plr = game.Players.LocalPlayer |
or
1 | plr = script.Parent.Parent.Parent.Parent.Parent -- mostly only works for UI. Not always 5. |
Also Works:
1 | local plr = game.Players.LocalPlayer -- only for LocalScripts. |
If this works, please accept my answer. Enjoy! :D
NOTE: This code will do the action below then any time the leaderstat stage value goes up by 1.
Edit: Use a script in ServerScriptService.
EDIT 2: Because this may not work:
1 | local plr = game.Players.LocalPlayer |
2 | local leaderstats 2 = plr:WaitForChild( "leaderstats" ) |
3 |
4 | if plr.leaderstats 2. Stage.Value + 1 then |
5 | print ( "value up" ) |
6 | end |
Otherwise, a simple solution is adding a:
1 | while wait(. 1 ) do |
On the top instead of a simple wait code.