Hey,
I’m new in data store so it’s really hard for me. I’m trying to make a data store with 3 values, Win/Cash/Medicine. So for doing this I saw a tutorial of Alvin Blox and copy exactly what is on the video but the script doesn’t save the cash (every print work ok but the print(“Data Saved”) work 1/2). Any error in output. Of course, I have activate data store on Roblox Studio. So what is wrong with this script. Oh and by the way, I have to make this 3 times to save each value separately or use table ?
Thanks for answer
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId.."-cash") or 0
print("Data load")
end)
if success then
cash.Value = data
else
print("Error while loading data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Cash.Value)
end)
if success then
print("Data saved")
else
print("Error while saving data")
warn(errormessage)
end
end)
Can you send screenshots of output apon leave and join please, also remember a good thing about PCall is you can encorperate it into a loop to try several times to save the data if it fails
Sorry but what is apon ? And where I have to put this loop on the script.
For Output, it look like that:
[12:53:00.169 - InsertService cannot be used to load assets from the client]
12:53:00.170 - Stack Begin
[12:53:00.171 - Script ‘Plugin_1292342678.PathfindingMaker.ButtonScript’, Line 13]
12:53:00.171 - Stack End
[Data load]
12:53:13.208 - Disconnect from 127.0.0.1|54911
Quick question to help you further in scripting, do you understand some of this Lua scripting, you really should not be dong this if you don’t and you should not just copy a script from someone unless you truly understand it.
Gonna reinforce this point, before you move onto datstoree first understand tables and how values work and can be manipulated, also do a bit of research into the data store api, find out what GetAsync SetAsync UpdateAsync do.