How can I find out how much a value has changed? Here is my script:
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Parent = player leaderstats.Name = "leaderstats" local points = Instance.new("IntValue") points.Parent = leaderstats points.Name = "Points" oldValue = player.leaderstats.Points.Value player.leaderstats.Points.Changed:Connect(function(newValue) local pointsChanged = newValue - oldValue print(pointsChanged) end) end)
This onlly gives me the value.... Not how much it has changed from the old value...
You never update the oldValue which is probably 0 so it will not change the new value.
Secondly you have cariables for the IntValue so use them.
Lastly oldValue should also be a local variable.
Example
-- you should use get service where possible -- incase the name if the service is changed game:GetService("Players").PlayerAdded:Connect(function(plr) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" local points = Instance.new("IntValue") points.Name = "Points" points.Parent = leaderstats local oldValue = points.Value -- use the variable points.Changed:Connect(function(newVal) print(newValue - oldValue) oldValue = newValue -- update the old value variable end) -- parent to the game last leaderstats.Parent = plr end)
I hope this helps.