#DataStore issue

1 messages · Page 1 of 1 (latest)

azure matrix
#

Ik there is better ways to do this but im just lazy. Issue is that it doesnt set the value to the or for example data.TeleportRadius or 40
It just sets to 0

#
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)
drifting aspen
#

This can very well just be a result of you saving it as 0 at some time during development

azure matrix
#

I even used removeAsync on my id

chrome jacinth
azure matrix