Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

3 comments

0

getPropertyChangedSignal

0

If your going to ask a question, at least look at the answers and pick which one solves it.

0

... That answer didn't solve ...

2 answers

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.

2 comments

0

I like this method for these kinds of questions.

0

Where would I place this local script? I placed it in Workspace, it didn't work.

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.

4 comments

0

It didn't work in serverscriptservice.

0

I bet your using a localscript. Check otherwise, check my edit.

0

Check my latest edit i found the solution!

0

*Check my simple solution at the bottom

This discussion is preserved as it was. New answers, comments, and votes are closed.