hello everyone, I have been trying to make a game in roblox for about 5 months, I have encountered a problem and I hope you can help me, I have 3 values in the leaderstats called JumpPower, Rebirths and Diamonds, Diamonds value is saved by datastore while jumppower and rebirths values are not. I really couldn’t understand why this is so and I couldn’t figure it out I hope you can help me thank you…
local DataStoreService = game:GetService("DataStoreService")
local CurrencyDataStore = DataStoreService:GetDataStore("Public")
local function SaveData(player)
local leaderstats = player:FindFirstChild("leaderstats")
local JumpPower = leaderstats and leaderstats:FindFirstChild("JumpPower")
local Diamonds = leaderstats and leaderstats:FindFirstChild("Diamonds")
local Rebirths = leaderstats and leaderstats:FindFirstChild("Rebirths")
if JumpPower and Diamonds and Rebirths then
local data = {
JumpPower = JumpPower.Value,
Diamonds = Diamonds.Value,
Rebirths = Rebirths.Value
}
local success, error1 = pcall(function()
CurrencyDataStore:SetAsync(tostring(player.UserId), data)
end)
if not success then
warn("Fail:", error1)
end
end
end
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local JumpPower = Instance.new("IntValue")
JumpPower.Name = "JumpPower"
JumpPower.Parent = leaderstats
local Diamonds = Instance.new("IntValue")
Diamonds.Name = "Diamonds"
Diamonds.Parent = leaderstats
local Rebirths = Instance.new("IntValue")
Rebirths.Name = "Rebirths"
Rebirths.Parent = leaderstats
local success, result = pcall(function()
return CurrencyDataStore:GetAsync(tostring(player.UserId))
end)
if success and result then
JumpPower.Value = result.JumpPower or humanoid.JumpHeight
Diamonds.Value = result.Diamonds or 0
Rebirths.Value = result.Rebirths or 0
else
JumpPower.Value = humanoid.JumpHeight
Diamonds.Value = 0
Rebirths.Value = 0
end
local function onJumpPowerChanged(newValue)
JumpPower.Value = newValue
humanoid.JumpPower = newValue
end
JumpPower.Changed:Connect(onJumpPowerChanged)
player.CharacterRemoving:Connect(function()
SaveData(player)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
SaveData(player)
end)
API service was open, I always pay attention to this, the problem is not related to this. I try constantly and constantly, but I cannot understand and solve the problem. The diamonds value is saved while the others are not. There are two codes related to rebirths and jumppower, which I think are independent of this code, but could the problem be related to this? I can’t think of any other option. Here is the codes basicly:
local player = game.Players.LocalPlayer
local JumpPower = player:WaitForChild("leaderstats"):WaitForChild("JumpPower")
local rebirths = player:WaitForChild("leaderstats"):WaitForChild("Rebirths")
local currentRebirth = 0
script.Parent.MouseButton1Click:Connect(function()
if JumpPower.Value >= 10 and currentRebirth == 0 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
currentRebirth = 1
elseif JumpPower.Value >= 100 and currentRebirth == 1 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
currentRebirth = 2
elseif JumpPower.Value >= 250 and currentRebirth == 2 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
currentRebirth = 3
elseif JumpPower.Value >= 400 and currentRebirth == 3 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
elseif JumpPower.Value >= 1200 and currentRebirth == 4 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
elseif JumpPower.Value >= 2500 and currentRebirth == 5 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
elseif JumpPower.Value >= 7500 and currentRebirth == 6 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
elseif JumpPower.Value >= 20000 and currentRebirth == 7 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
elseif JumpPower.Value >= 50000 and currentRebirth == 8 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
elseif JumpPower.Value >= 125000 and currentRebirth == 9 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
elseif JumpPower.Value >= 350000 and currentRebirth == 10 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
elseif JumpPower.Value >= 800000 and currentRebirth == 11 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
elseif JumpPower.Value >= 1000000 and currentRebirth == 12 then
rebirths.Value = rebirths.Value + 1
JumpPower.Value = 0
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.JumpPower = 0.2
end
end
end)
...
here is the second script
```lua
local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local debounce = false
-- JumpPower değerindeki değişiklikleri takip eden fonksiyon
local function onClick()
if debounce == false then
debounce = true
plr.leaderstats.JumpPower.Value += math.max(1, plr.leaderstats.Rebirths.Value * 10)
script.Parent.Parent.Sound:Stop()
script.Parent.Parent.Sound:Play()
debounce = false
end
end
local function onJumpPowerChanged(newValue)
char.Humanoid.JumpPower = newValue
end
-- JumpPower değeri değiştiğinde onJumpPowerChanged fonksiyonunu çalıştıran fonksiyon
plr.leaderstats.JumpPower.Changed:Connect(onJumpPowerChanged)
script.Parent.Activated:Connect(function()
onClick()
end)
mouse.Button1Down:Connect(function()
onClick()
end)
...