I am having an error when I try to detect IntValue changes for a player.
01 | local coinStore = game:GetService( "DataStoreService" ):GetDataStore( "coinsv1" ) |
02 | local jumpAmountStore = game:GetService( "DataStoreService" ):GetDataStore( "jumpv1" ) |
03 | local levelStore = game:GetService( "DataStoreService" ):GetDataStore( "levelv1" ) |
04 |
05 | game.Players.PlayerAdded:Connect( function (p) |
06 | local leaderstats = Instance.new( "Folder" , p) |
07 | local coins = Instance.new( "IntValue" , leaderstats) |
08 | local levels = Instance.new( "IntValue" , leaderstats) |
09 | local jumpAmount = Instance.new( "IntValue" , leaderstats) |
10 | leaderstats.Name = "leaderstats" |
11 | coins.Name = "Coins" |
12 | levels.Name = "Level" |
13 | jumpAmount.Name = "Jumps" |
14 | coins.Value = 0 |
15 | levels.Value = 1 |
The error is at line 46 and 60. The error is attempt to perform arithmetic (add) on nil and number
.
On line 41, you set recentcoins variable to nil . So on line 46 and 60, it tries to add 20 and 10 to a nil value, causing the error. Set recentcoins to 0 instead of just nil.
EDIT: It's also the case with line 52. Fix that too.