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:

wait(2)

if game.Players.Player.leaderstats.Stage.Value +1 then
    print("value up")
end
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.

local stage = game.Players.LocalPlayer.leaderstats.Stage

stage:GetPropertyChangedSignal("Value"):Connect(function()  
print("value changed")
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

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

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.

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

I commonly use a connect to player system:

plr = game.Players.LocalPlayer

or

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

Also Works:

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:

local plr = game.Players.LocalPlayer
local leaderstats2 = plr:WaitForChild("leaderstats")

if plr.leaderstats2.Stage.Value +1 then
print("value up")
end

Otherwise, a simple solution is adding a:

while 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