So basically when a value changes like maybe a kill value in the leaderstats changes, the script tells me by how much, like your kills was 2 and you got 4 kills from an explosion, it would say +4 kills, but i currently dont know how to do that.
i tried looking through the devforum and i cant seem to find any posts about my problem, sorry if im describing this badly this is my first post as i dont like asking help, if your confused im happy to explain more.
All isntances have a Instance:GetPropertyChangedSignal(PropertyName) function which returns the event fired when that particular property is fired. For example, to detect a value change you would do:
local value = game.Workspace.NumberValue
value:GetPropertyChangedSignal("Value"):Connect(function()
print("New value: " .. value.Value)
end)
wait(5)
value.Value = 4
After 5 seconds, you should see this in the console:
it would print the new value rather than printing how much it added i tried adding variables to compare it but i cant seem to get a grasp on how to actually compare it and do the math
Yes but how would i be able to compare the old value to the new value? i know there is < and > but im looking for how much the new value added to the old value
I mean you can indeed store the old value and compare it to the new value. Let me give you a little example of how you can make this:
First you need to make two variables and in this example I’ll name one oldVar and one newVar. At the start both oldVar and newVar should be equal to 0 as the player hasn’t made any kills yet. If the player manages to make a kill it should add 1 to the newVar. Then you can calculate the difference by simply substracting the new value (newVar) from the old value (oldVar)