Im new to Roblox Studios scripting so to learn some basic fundamentals I decided to make a simulator like game as practice. I wanted to make a script which saved the players progress as he/she progressed. This is what I scripted down, but when I tried testing out the code the players progress wouldn’t save. I checked the output monitor and didn’t get any error. Any idea what I did wrong and how to fix it? The script is a regular script inside of ServerScriptService.
local DS = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "id_"..plr.userId
local save1 = plr.leaderstats.Sugar
local save2 = plr.leaderstats.Cash
local GetSaved = DS:GetAsync(plrkey)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
else
local NumberForSaving = {save1.Value, save2.Value}
DS:GetAsync(plrkey, NumberForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
DS:SetAsync("id_"..plr.userId, {plr.leaderstats.Sugar.Value, plr.leaderstats.Cash.Value})
end)
Try using pcall() it tell show if theres error or not…
for exp:
local succ, err = pcall(function()
-- Put the :GetAsync function here
end)
if succ then
-- code
elseif err then
warn(err) -- Shows if theres a error.
end
And try putting all of them in one script instead of making 2 scripts
Try saving a value before you leave the game and see if that solves your issue. It may be that your script is fully functional, but is just not reading the values in time before you leave the game.
I was having troubles logging into studio so when I did this appeared Failed to load plugin permissions from cloud: loadPluginPermissionsPageAsync(0, 10): HTTP error: HttpRequest “PluginLoader::loadAllPluginPermissionsAsync()”: Got network error status: 502. I haven’t done what you said to do yet though. Does thsi have anything to do with it?
Well there’s a possibility that you don’t have your setting enabled for HTTP requests. So I advise you open up game settings in studio, and enable http requests. You should know whichever one you need to enable because it will note that enabling it allows datastores to be used.