Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make something happen once the player's value goes up?

Asked by 5 years ago

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:

1wait(2)
2 
3if game.Players.Player.leaderstats.Stage.Value +1 then
4    print("value up")
5end
0
getPropertyChangedSignal Spiritlotus 151 — 5y
0
If your going to ask a question, at least look at the answers and pick which one solves it. RobloxGameingStudios 145 — 5y
0
... That answer didn't solve ... GamingWithFlight 80 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

like I commented, use GetPropertyChangedSignal. im on phone rn so I cant test this but this is how it works.

1local stage = game.Players.LocalPlayer.leaderstats.Stage
2 
3stage:GetPropertyChangedSignal("Value"):Connect(function() 
4print("value changed")
5end)

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

1stage.Changed:Connect(function()
2print("value changed")
3end)

and this would check to see if any property at all, not just Value has changed. but a leaderstat only has Value.

0
I like this method for these kinds of questions. KDarren12 705 — 5y
0
Where would I place this local script? I placed it in Workspace, it didn't work. GamingWithFlight 80 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Assuming this script is going in ServerScriptService. You wrote the script wrong. It is supposed to be LocalPlayer not Player.

1if game.Players.LocalPlayer.leaderstats.Stage.Value +1 then
2print("value up")
3end

I commonly use a connect to player system:

1plr = game.Players.LocalPlayer

or

1plr = script.Parent.Parent.Parent.Parent.Parent -- mostly only works for UI. Not always 5.

Also Works:

1local 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:

1local plr = game.Players.LocalPlayer
2local leaderstats2 = plr:WaitForChild("leaderstats")
3 
4if plr.leaderstats2.Stage.Value +1 then
5print("value up")
6end

Otherwise, a simple solution is adding a:

1while wait(.1) do

On the top instead of a simple wait code.

0
It didn't work in serverscriptservice. GamingWithFlight 80 — 5y
0
I bet your using a localscript. Check otherwise, check my edit. RobloxGameingStudios 145 — 5y
0
Check my latest edit i found the solution! RobloxGameingStudios 145 — 5y
0
*Check my simple solution at the bottom RobloxGameingStudios 145 — 5y

Answer this question