#Dataloss issue

30 messages · Page 1 of 1 (latest)

upper prawn
#

yes roblox datastore have multiple problems

#

i recommend u to use modules like profileservice

#

search it up on yt there a lot of tutorials of how to use it

#

👍

#

no what

#

u prefer to the players gettin data resetting and duping

#

u would did that first

#

just change it the way u can because problems of datastore will cause brain dmg lol

uneven geode
#

i am getting the same problem idk why it happens

upper prawn
#

yep roblox has a loooot of problems with datastores

#

i experienced it too but using profileservice fixed it 👍

#

lol

#

goofy emoji

uneven geode
#

this is my script: ```
script.Parent.Touched:Connect(onTouch)
game.Players.PlayerRemoving:Connect(savePlayerData)
game.Players.PlayerAdded:Connect(loadPlayerData)

umbral depotBOT
#

studio** You are now Level 7! **studio

upper prawn
#

you should re-do all the save system and leaderstats

uneven geode
#

bruh wait

upper prawn
#

i personally recommend researching on youtube

#

its very easy too

#

but fr do it

#

🙏

#

fix a lot of brain dmg problems

#

ProfileService is called the module

#

search it up and hope it helps

uneven geode
#

ok i ll search for it

#
local starCoinsDS = DataStoreService:GetDataStore("starCoinsDS")

local RespawnTime = 5 

function savePlayerData(player)
    local leaderstats = player:FindFirstChild("leaderstats")
    if leaderstats then
        local starCoins = leaderstats:FindFirstChild("starCoins")
        if starCoins then
            print("data before saved")
            starCoinsDS:SetAsync(player.UserId .. "_starCoins", starCoins.Value)
            print("data after saved")

        end
    end
end

function loadPlayerData(player)
    local success, result = pcall(function()
        return starCoinsDS:GetAsync(player.UserId .. "_starCoins")
    end)
    if success and result ~= nil then
        local leaderstats = player:FindFirstChild("leaderstats")
        print("data loaded")
        if leaderstats then
            local starCoins = leaderstats:FindFirstChild("starCoins")
            if starCoins then
                starCoins.Value = result
            end
        end
    end
end

function onTouch(otherPart)
    local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
    if player then
        local leaderstats = player:FindFirstChild("leaderstats")
        if not leaderstats then
            return
        end

        local starCoins = leaderstats:FindFirstChild("starCoins")
        if starCoins then
            starCoins.Value = starCoins.Value + 1 
        end
        script.Parent.CanTouch = false
        script.Parent.Transparency = 1
        wait(RespawnTime)
        script.Parent.CanTouch = true
        script.Parent.Transparency = 0

    end
end


script.Parent.Touched:Connect(onTouch)
game.Players.PlayerRemoving:Connect(savePlayerData)
game.Players.PlayerAdded:Connect(loadPlayerData)```
#

just see the savedata function

#

but why it works better than dss

real island
#

It is expected that datastore functions will fail from time to time. If not handled you will experience dataloss. From Roblox docs:

Functions like SetAsync() that access a data store's contents are network calls that may occasionally fail. As shown above, it's recommended that these calls be wrapped in pcall() to catch and handle errors.

The 3rd party library: ProfileService for example repeats saving until it succeeds: https://github.com/MadStudioRoblox/ProfileService/blob/master/ProfileService.lua#L966

You should check the result of the pcall (by adding in front local success, updatedData = pcall(..) like the Roblox docs show: https://create.roblox.com/docs/cloud-services/datastores#updating-data

Then you can try saving again if success is not true