storing or loading from data store not working, why?
i am trying to save player data to data store using a script i found and modified
The original script is from this website
I modified it so that it would store three values
Experience as IntValue
Rank as StringValue
Bucks as IntValue
before i modified the script it worked but now it doesn't work anymore, i wonder have i referenced the data i want to store correctly?
my modified script is beloew
002 | local DataStoreService = game:GetService( "DataStoreService" ) |
004 | local playerData = DataStoreService:GetDataStore( "PlayerData" ) |
008 | local function onPlayerJoin(player) |
010 | local leaderstats = Instance.new( "Folder" ) |
012 | leaderstats.Name = "leaderstats" |
014 | leaderstats.Parent = player |
016 | local bucks = Instance.new( "IntValue" ) |
020 | bucks.Parent = leaderstats |
022 | local exp = Instance.new( "IntValue" ) |
024 | exp.Name = "Experience" |
026 | exp.Parent = leaderstats |
029 | local rank = Instance.new( "StringValue" ) |
033 | rank.Parent = leaderstats |
037 | local playerUserId = "Player_" .. player.UserId |
039 | local data = playerData:GetAsync(playerUserId) |
043 | bucks.Value = data [ 'Bucks' ] |
045 | exp.Value = data [ 'Experience' ] |
047 | rank.Value = data [ 'Rank' ] |
065 | local function create_table(player) |
067 | local player_stats = { } |
069 | for _, stat in pairs (player.leaderstats:GetChildren()) do |
071 | player_stats [ stat.Name ] = stat.Value |
081 | local function onPlayerExit(player) |
085 | local player_stats = create_table(player) |
087 | local success, err = pcall ( function () |
089 | local playerUserId = "Player_" .. player.UserId |
091 | playerData:SetAsync(playerUserId, player_stats) |
099 | warn( 'Could not save data!' ) |
107 | game.Players.PlayerAdded:Connect(onPlayerJoin) |
109 | game.Players.PlayerRemoving:Connect(onPlayerExit) |