Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Roblox DataStore wont save or even remember my UserId?

Asked by 3 years ago

`So I've been working on a Roblox Evolution Simulator game and I'm trying to make a level system. I need to have the base max Xp per level be 1000. I can right a simple script if everything's base is 0 but if there is a number above 0 it just won't work! I've tried in Studio and in game. Also I don't use leaderstat because I have an Xp bar. Wont save, I've looked through every possible forum page it just wont work! Here's my code:

local playerData = DataStoreService:GetDataStore("PlayerData")

local function onPlayerJoin(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name='lead'
    leaderstats.Parent=player

    local xp = Instance.new("IntValue", leaderstats)
    xp.Name='Exp'

    local level = Instance.new("IntValue", leaderstats)
    level.Name='Level'

    local maxExp = Instance.new("IntValue", leaderstats)
    maxExp.Name='Max'


    local playerUserId = 'Player....'..player.UserId
    local data = playerData:GetAsync(tostring(playerUserId))
    if data  then
        xp.Value = data['Exp']
        print(data["Exp"])
        game.StarterGui.ScreenGui.One.Text=data["Exp"]
        level.Value = data['Level']
        game.StarterGui.ScreenGui.Two.Text=data["Level"]
        print(data["Level"])
        maxExp.Value = data['Max']
        game.StarterGui.ScreenGui.Three.Text=data["Max"]
        print(data['Max'])
    else
        xp.Value=0
        level.Value=0
        maxExp.Value=1000
        game.StarterGui.ScreenGui.Three.Text='Hi'
        print("first time")
    end

end

local function create_table(player)
    local player_stats = {}
    for _, stat in pairs(player.lead:GetChildren()) do
        player_stats[stat.name] = stat.value
    end
        return player_stats
end

local function onPlayerExit(player)
    local player_stats = create_table(player)
    local success, err = pcall(function()
        local playerUserId = 'Player....'..player.UserId
        playerData:SetAsync(tostring(playerUserId), player_stats)
    end)

    if not success then
        warn('Could not save data')
    end
end


game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)``
0
Well, how are you incrementing your values? In a LocalScript? MarkedTomato 810 — 3y

Answer this question