Hi! So I’m making a lifting simulator game with the leaderboard stats (Strength, KillStreak, and Rank)
Whenever I change any of these stats, it doesn’t save when I rejoin the game. To lift (increases Strength) I use a local script as well as for rebirthing (changing rank) is in a local script too.
Here is the script I use to create the leaderstats, it used to save in a few of my other games, I don’t get why it wouldn’t be saving now.
local DataStoreService = game:GetService("DataStoreService")
local data = DataStoreService:GetDataStore("Strength_2")
local DatedPlayer = DataStoreService:GetDataStore("KillStreak_2")
local PlayerData = DataStoreService:GetDataStore("Rank_2")
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local strength = Instance.new("NumberValue")
strength.Name = "Strength"
strength.Parent = leaderstats
local kills = Instance.new("IntValue")
kills.Name = "KillStreak"
kills.Parent = leaderstats
local rank = Instance.new("StringValue")
rank.Name = "Rank"
rank.Parent = leaderstats
local playerUserId = "Player_" .. player.UserId
local StrengthStat = data:GetAsync(playerUserId)
local KillStat = DatedPlayer:GetAsync(playerUserId)
local RankStat = PlayerData:GetAsync(playerUserId)
if StrengthStat then
strength.Value = StrengthStat['Strength']
else
strength.Value = 0
end
if KillStat then
kills.Value = KillStat['Killstreak']
else
kills.Value = 0
end
if RankStat then
rank.Value = RankStat['Rank']
else
rank.Value = "Meteoroid"
end
end
local function create_table(player)
local player_stats = {}
for _, stat in pairs(player.leaderstats: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
data:SetAsync(playerUserId, player_stats)
DatedPlayer:SetAsync(playerUserId, player_stats)
PlayerData:SetAsync(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)
Thank you!!