I'm trying to make a save script for my game. The values(stats) are in replicated storage. I'm still a beginner intermediate scripter so I only know about saving leaderstats. I need some help with making a save script. I tried editing a data persistence script but it didn't work.
function onPlayerEntered(player)
wait()-- Change to wait for player longer.
player:WaitForDataReady()
repeat wait() until game.ReplicatedStoarage.StatsFolder:FindFirstChild(player.Name).Muscle.Value
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = game.ReplicatedStoarage.StatsFolder:FindFirstChild(player.Name).Muscle.Value
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(score[i].Name)
wait()
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end
function onPlayerLeaving(player)
if game.ReplicatedStorage:findFirstChild("StatsFolder") then
local score = game.ReplicatedStoarage.StatsFolder:FindFirstChild(player.Name).Muscle.Value
for i = 1,#score do
player:SaveNumber(score[i].Name,score[i].Value)
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)

6 comments
ReplicatedStorage is only for the current server. DataPresistance is deprecated for security reasons. What do you think is left?
^ Data Store
ok data store.. so do i move all stats to server storage?
doesn't rlly matter
just make it a saving string manipulation
and how would i do that? Remember, I'm still a beginner