Hello DevForum,
I am looking for assistance on a script which I cant seem to get to work.
I am working on a supernatural based game in which the script im working in is grace, Grace gives angels there powers and im trying to make it so if the players grace is under 100 then there grace will start growing every 2 seconds by 5.
I am using a GetPropertyChangedSignal() for this
local Grace = Instance.new("IntValue")
Grace.Name = "Grace"
Grace.Parent = plr
Grace.Value = 20
local MaxValue = 100
repeat wait(1) Grace.Value = Grace.Value + 20 until Grace.Value == MaxValue
Grace:GetPropertyChangedSignal("Value"):Connect(function()
if Grace.Value > MaxValue then
repeat wait(1) Grace.Value = Grace.Value + 5 until Grace.Value == MaxValue
end
end)
```
You could just replace the == with >=, as that’ll detect when it’s greater than/equal to the value it’s searching for
Also, why are you using a GetPropertyChangedSignal Event? The Dev API references an easier way by using the .Changed Event instead:
local MaxValue = 100
local Grace = Instance.new("IntValue")
Grace.Name = "Grace"
Grace.Parent = plr
Grace.Value = 20
repeat
wait(1)
Grace.Value = Grace.Value + 20
until Grace.Value >= MaxValue
Grace.Changed:Connect(function(NewValue)
if NewValue > MaxValue then
repeat
wait(1)
Grace.Value = Grace.Value + 20
until Grace.Value >= MaxValue
end
end)
Hey so what im trying to do is make it so later in time a player can steal grace but a player gains it back slowly over time, But ive tried your script and the grace value remains the same when I set it to a lower value. It did not work.
Oh I see, alright for this instance you have to reference this line
To this instead:
if NewValue < MaxValue then
So that way the NewValue is less than the MaxValue so it can slowly increase the value by 20 per second