#I need DATASAVER Script

1 messages · Page 1 of 1 (latest)

feral magnet
#

I will tell you my game based

#

So my game is based rng, where you have to roll button to roll auras

#

for example i click roll

#

Thats great right, now

#

When i leave game and join back my data is not saved

#

I tried using ai

#

But its not working

#

He gave me this script:

#

-- Step 1: Get necessary services
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")

-- Step 2: Define the DataStore
local testDataStore = DataStoreService:GetDataStore("TestSaveData")

-- Step 3: Function to save player data
local function saveData(player)
print("[SERVER] Attempting to save data for player:", player.Name)

local success, errorMessage = pcall(function()
    -- Save a simple number to the DataStore
    local userId = tostring(player.UserId)
    print("[SERVER] Saving data for user ID:", userId)
    testDataStore:SetAsync(userId, 42) -- Example value
end)

if success then
    print("[SERVER] Data saved successfully for player:", player.Name)
else
    warn("[SERVER] Failed to save data for player:", player.Name, "Error:", errorMessage)
end

end

-- Step 4: Function to load player data
local function loadData(player)
print("[SERVER] Attempting to load data for player:", player.Name)

local success, savedData = pcall(function()
    -- Load the data from the DataStore
    return testDataStore:GetAsync(tostring(player.UserId))
end)

if success and savedData then
    print("[SERVER] Data loaded successfully for player:", player.Name, "Data:", savedData)
else
    warn("[SERVER] Failed to load data for player:", player.Name, "Error:", savedData)
end

end

-- Step 5: Connect to Player events
Players.PlayerRemoving:Connect(saveData) -- Save data when a player leaves
Players.PlayerAdded:Connect(loadData) -- Load data when a player joins

fading burrow
#

Go look up a tutorial please, chat gpt or whatever gave you an example script that just saves the number "42", you didn't connect this to your other scripts

feral magnet
#

Tutorial?, like what should i ask youtube to search

fading burrow
feral magnet
#

Alright, but all those tutorials are for like obbys

#

i will see now

#

thanks

fading burrow
feral magnet
#

Thanks for helping

haughty depot
#

please do not rely on ai

bright grail
#

only use it as a tool for revision or to point you in a direction

#

Use a module like Profile Service or Profile Store as they make the process much easier, here is a vid that can help

📒 ProfileStore is a Roblox DataStore wrapper that streamlines auto-saving, session locking and a few other features for the game developer. ProfileStore’s source code runs on a single Module Script. In this Roblox Studio Tutorial, I show how to use ProfileStore, and how to save data with ProfileStore.

--------------------------------------...

▶ Play video
fading burrow
bright grail
fading burrow
bright grail
#

pls

fading burrow
bright grail
bright grail
fading burrow
fading burrow
#

The default network owner for any character is the player

bright grail
#

okay, thanks I did not know that

fading burrow