#DataStore issue
1 messages · Page 1 of 1 (latest)
local DataStoreService = game:GetService("DataStoreService")
local PlayerStats = DataStoreService:GetDataStore("PlayerStats")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local Coins = Instance.new("NumberValue")
Coins.Parent = leaderstats
Coins.Name = "Coins"
local Upgrades = Instance.new("Folder")
Upgrades.Parent = player
Upgrades.Name = "Upgrades"
local TeleportRadius = Instance.new("NumberValue")
TeleportRadius.Parent = Upgrades
TeleportRadius.Name = "TeleportRadius"
local CoinsGain = Instance.new("NumberValue")
CoinsGain.Parent = Upgrades
CoinsGain.Name = "CoinsGain"
local success, data = pcall(function()
return PlayerStats:GetAsync(player.UserId)
end)
if success and data ~= nil then
Coins.Value = data.Coins or 0
TeleportRadius.Value = data.TeleportRadius or 40
CoinsGain.Value = data.CoinsGain or 1
else
Coins.Value = 0
TeleportRadius.Value = 40
CoinsGain.Value = 1
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local data = {
Coins = player.leaderstats.Coins.Value,
TeleportRadius = player.Upgrades.TeleportRadius.Value,
CoinsGain = player.Upgrades.CoinsGain.Value
}
local success, errorMessage = pcall(function()
PlayerStats:SetAsync(player.UserId, data)
end)
if not success then
warn(errorMessage)
end
end)
Well this just means that data.TeleportRadius = 0.
The or never gets used as data.TeleportRadius exists, so it won't then default to 40
This can very well just be a result of you saving it as 0 at some time during development
No thats the whole code my game has.
I even used removeAsync on my id
Maybe try to print the data saved on your key ?
Its 0
▼ {
["Coins"] = 0,
["CoinsGain"] = 0,
["TeleportRadius"] = 0
} Instance - Server - leaderstats:26