#leaderstats wont even appear unless i remove datastore and datastoreservice

1 messages · Page 1 of 1 (latest)

twin iron
#
local datastore=dss:GetDataStore('DataStore')
game.Players.PlayerAdded:Connect(function(player)
    local leaderstats=Instance.new('Folder')
    leaderstats.Parent=player
    leaderstats.Name='leaderstats'
    local coins=Instance.new('IntValue')
    coins.Parent=leaderstats
    coins.Name='coins'
    local success,data =pcall(function()
        return datastore:GetAsync(player.UserId)
    end)
    if success and data then
        coins.Value=data
    else
        warn('cant find coins profile for'.. player.Name)
    end
end)
game.Players.PlayerRemoving:Connect(function(player)
    local coins=player:FindFirstChild('leaderstats'):FindFirstChild('coins')
    local success,err=pcall(function()
        datastore:SetAsync(player.UserId,coins.Value)
    end)
    if not success then
        warn('cant save coins profile')
    end
end)```
#

even asked cgpt to help and its supposed to work fine, also restarted my pc and studio (first time doing this also so ik its choppy, still cantget the hang of them)

#

also by datastore I just mean the first 2 lines of the code..