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

Why doesnt the data in my roblox simulator game save?

Asked by 2 years ago
Edited 2 years ago

So I go in my game, do a test on it (not in roblox studio) and it doesnt save!


local serverStorage = game:GetService("ServerStorage")
local DataStore = game.GetService("DataStoreService"):GetDataStore("PlayerSave3")

game.Players.PlayerAdded:Connect(function(player)

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local strength = Instance.new("NumberValue")
strength.Name = "Strength"
strength.Parent = leaderstats

local rebirths = Instance.new("IntValue")
rebirths.Name = "Rebirths"
rebirths.Parent = leaderstats

local dataFolder = Instance.new("Folder")
dataFolder.Name = player.Name
dataFolder.Parent = serverStorage.RemoteData

local debounce = Instance.new("BoolValue")
debounce.Name = "Debounce"
debounce.Parent = dataFolder

local strengthData, rebirthsData

local success,errormessage = pcall(function()
    strengthData = DataStore:GetAsync("strength-"..player.UserId)
    rebirthsData = DataStore:GetAsync("rebirths-"..player.UserId)
end)

    if success then
        if strengthData then
            strength.Value = strengthData
            rebirths.Value = rebirthsData
        end
    end

end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errormessage = pcall(function()
    DataStore:SetAsync("strength-"..player.UserId,player.leaderstats.Strength.Value)    
    DataStore:SetAsync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value)
    end)
end)

btw actually look at the source. That is the ORIGINAL code

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

I FIXED THE CODE. Thanks i guess.

Ad

Answer this question