I am having an error when I try to detect IntValue changes for a player.
local coinStore = game:GetService("DataStoreService"):GetDataStore("coinsv1")
local jumpAmountStore = game:GetService("DataStoreService"):GetDataStore("jumpv1")
local levelStore = game:GetService("DataStoreService"):GetDataStore("levelv1")
game.Players.PlayerAdded:Connect(function(p)
local leaderstats = Instance.new("Folder", p)
local coins = Instance.new("IntValue", leaderstats)
local levels = Instance.new("IntValue", leaderstats)
local jumpAmount = Instance.new("IntValue", leaderstats)
leaderstats.Name = "leaderstats"
coins.Name = "Coins"
levels.Name = "Level"
jumpAmount.Name = "Jumps"
coins.Value = 0
levels.Value = 1
jumpAmount.Value = 0
local jumpPower
p.CharacterAdded:Connect(function(c)
jumpPower = c.Humanoid.JumpPower
c.Humanoid.JumpPower = jumpPower
end)
local data
local datatwo
local datathree
local success, errormessage = pcall(function()
data = coinStore:GetAsync(p.UserId.."-coins")
datatwo = jumpAmountStore:GetAsync(p.UserId.."-jumps")
datathree = levelStore:GetAsync(p.UserId.."-level")
end)
if success then
coins.Value = data
levels.Value = datathree
jumpAmount.Value = datatwo
else
print(errormessage)
end
local recentcoins
jumpAmount.Changed:Connect(function()
if jumpAmount.Value == datatwo + 20 then
levels.Value = levels.Value + 1
recentcoins = jumpAmount.Value
elseif jumpAmount.Value == recentcoins + 20 then
levels.Value = levels.Value + 1
recentcoins = jumpAmount.Value
end
end)
local recentjumps
jumpAmount.Changed:Connect(function()
if jumpAmount.Value == datatwo + 10 then
local jumps = jumpAmount.Value / 10
jumps = jumps + 50
local cjump = p.Character.Humanoid.JumpPower
cjump = jumps
recentjumps = jumpAmount.Value
elseif jumpAmount.Value == recentjumps + 10 then
local jumps = jumpAmount.Value / 10
jumps = jumps + 50
local cjump = p.Character.Humanoid.JumpPower
cjump = jumps
recentjumps = jumpAmount.Value
end
end)
end)
The error is at line 46 and 60. The error is attempt to perform arithmetic (add) on nil and number.
This may be a simple error, as I’ve been coding for about 6 and a half hours now, so I may have just made a typo.
Thanks!
