Hi fellow developers!
So I created a currency for my game called “DevPoints” and I saved it to the player’s leaderstats. In another script, I also created some variables and a loop to make the amount of DevPoints a player has rise by 3 every 5 seconds. Moreover, I attempted to save the entirety of this to the
DataStoreService. I used
pcall to help me, but for some reason, the
DataStore didn’t work. I tried disabling the script that made the DevPoints increase, but that didn’t seem to work either. Plus, nothing printed in the output, so that made it even more confusing.
Both of these server scripts are located in the
ServerScriptService. Here’s the
-- Create currency called "DevPoints" and put in player's leaderstats, then save to DataStore 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 devpoints = Instance.new("IntValue") devpoints.Name = "DevPoints" devpoints.Parent = leaderstats local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(player.UserId.."-devpoints") end) if success then devpoints.Value = data else print("An error occurred while retreiving your data.") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() myDataStore:SetAsync(player.UserId.."-devpoints",player.leaderstats.DevPoints.Value) end) if success then print("Player data successfully saved!") else print("An error occurred while saving your data.") warn(errormessage) end end)
Not sure what’s wrong with it; everything seems correct. If you’d like to see the DevPoints increase script, just let me know, although I’m pretty sure it’s not needed to solve the
Thanks for reading!