#I need DATASAVER Script
1 messages · Page 1 of 1 (latest)
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
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
Tutorial?, like what should i ask youtube to search
"roblox datastore service tutorial"
Yet you will still learn shit like inter-script communication (and hopefully also cross client-server-boundary communication)
Finally i asked roblox asistent it helped me
Thanks for helping
please do not rely on ai
Never use ai to make code logic brother😭
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.
--------------------------------------...
Learning how to set them up properly is way more useful in the long run
for a beginner I think a library is useful and can help you enhance your knowledge on other coding while still giving a little focus to how something like data saving works
Yet datasaving also often makes you think about proper data management (and also a bit about proper replication)
bro can you help explain to the guy on the "tp to spawn" scripting-help request why he needs to make a server script
pls
Please learn about network ownership
Okay I've heard of that but I've never looked into it could you explain it real quick
also isn't it just simply better in this case to use server sided tps instead of client to prevent cheating?
Any assembly (basically, any mixture of unachored parts) have a network owner, this defaults to the server. If you give network ownership to a player, then you can modify stuff like it's position (or cframe) on the client, and those changes replicate to the server
Any exploiter can teleport already, unless you actually make server sided checks to prevent it
The default network owner for any character is the player
okay, thanks I did not know that
Anyways, as always, trust is good. Checking is better. A very simple test can show off my "theory"