I am making a game where you gain +1 jump per second. The problem i am having is that the jump stat is not saving. Here is my code.
local function addJump(hum, Wins, plr, Jump)
spawn(function()
while wait(1) do
hum.JumpHeight += 1
Wins.Value = plr.leaderstats.Wins.Value
if Wins.Value >= 1 then
hum.JumpHeight = hum.JumpHeight + Wins.Value
end
end
end)
end
local DSS = game:GetService(“DataStoreService”)
local myDSS = DSS:GetDataStore(“MyDataStore”)
local dataStore = game:GetService(“DataStoreService”):GetDataStore(“DataStore”)
game.Players.PlayerAdded:Connect(function(plr)
local jumpH
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Parent = leaderstats
local Jump = Instance.new("IntValue")
Jump.Name = "Jump"
Jump.Parent = leaderstats
local plrid = "id_"..plr.userId
local save1 = plr.leaderstats.Wins
local save2 = plr.leaderstats.Jump
local GetSaved = dataStore:GetAsync(plrid)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
else
local NumberforSaving = {save1.Value, save2.Value}
dataStore:GetAsync(plrid, NumberforSaving)
end
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
if jumpH then
hum.JumpHeight = jumpH
end
addJump(hum, Wins, plr, Jump)
hum.Died:Connect(function()
jumpH = hum.JumpHeight
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
dataStore:SetAsync("id_"..plr.userId, {plr.leaderstats.Wins.Value, plr.leaderstats.Jump.Value})
print("wins = ", plr.leaderstats.Wins.Value)
print("jump = ", plr.leaderstats.Jump.Value)
end)
game:BindToClose(function()
for i, players in pairs(game.Players:GetChildren()) do
players:Kick(“server closed”)
end
end)
This is the output
The jump doesn’t save
also idk if this matters but i have my character JumpHeight set to 25