You made sure to put curly braces for every GetAsync and SetAsync command right?
Could you also send a reply of your updated code?
Did you enable API Services and HTTP requests?
I enabled API Services but I don’t know where I can enable HTTP requests.
Also this is my updated code:
local CPoints = game.Workspace.Room1.Checkpoints
local CBoxes = game.Workspace.Room1.Checkboxes
local StageStore = game:GetService("DataStoreService"):GetDataStore("StageStore")
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Parent= leaderstats
local StageData
local success, errormsg = pcall(function()
StageData = StageStore:GetAsync(player.UserId.."-Stage", {player.leaderstats.Stage.Value})
end)
if stage.Value ~= nil then
stage.Value = StageStore
end
if success then
print("Data loaded.") --Inclouded for troubleshooting so I can see wether the Data was loaded
print(StageStore:GetAsync(player.UserId.."-Stage", {player.leaderstats.Stage.Value})) --Included for troubleshooting and my attempt to print out the current value of the DataStore
else
print(errormsg)
end
player.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
wait()
char:MoveTo(CPoints[stage.Value].Position)
hum.Touched:Connect(function(hit)
if hit.Parent == CBoxes then
if tonumber(hit.Name) == stage.value + 1 then
stage.Value = stage.Value + 1
end
end
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormsg = pcall(function()
StageStore:SetAsync(player.UserId.."-Stage", {player.leaderstats.Stage.Value})
end)
if success then
print("Data saved.") --Inclouded for troubleshooting so I can see wether the Data was saved
print(StageStore:GetAsync(player.UserId.."-Stage", {player.leaderstats.Stage.Value})) --Included for troubleshooting and my attempt to print out the current value of the DataStore
else
print(errormsg)
end
end)
You can enable HTTP requests the same way you enabled API settings
HTTP requests is right above API settings.
HTTP requests are important for off-roblox communicating, including but not limited to data storage.
If you want to learn more about it you can go here to the API reference:
HttpService.
To enable HTTP requests, go to File > Game Settings > Security and toggle ‘Allow HTTP Requests’
Game Settings is grayed out for me so I cant click it.
Could you send a picture of what you mean?
If Game Settings is grayed out try closing and restarting Roblox Studio
If its grayed out for you in Files, you could also press home on your Ribbon bar and press game settings
Okay, I can access the Game Settings over the Ribbon bar and enabled the Requests.
Did it work?
zzzzzzzzzzzzzzzzzz
No.
zzzz zzzzzzz zzzzzzzzzzzzzzzz
And you tested it in an actual Roblox game too right?
Yes, I did that.
zzzzzzzzzzzzzz
In another script try putting this:
game:BindToClose(function()
if game:GetService("RunService"):IsStudio()then
wait(6)
else
wait(35)
end
end)
I found this script off another page on the devforum
The game could be closing too quickly before saving data
Here it is if you want to check that thread out
I found out something interesting although I don’t if it helps.
The part of the script with the CharacterAdded part teleports the player to the Checkpoint with the name of the Value of the leaderstats.Stage.Value.
So I went and added stage.Value= 1 when creating the leaderstats folder.
And now when i load the game I get an error because the game wants to teleport me to the Checkpoint with the Name 0 despite me setting the Value in leaderstas to 1 (It cant be 0).
So my conclusion from this is that the game doesn’t save the Data properly so it loads the number 0 althoug like I said early the Value can’t be 0)
Dont know if you understand what I mean.
Yea I see what you mean
No idea how to help you because I don’t know how your game is organized
There could be some other script that is countering this
Have you tried just rewriting the script entirely?
Would recommend using two scripts instead of just one where one script makes the folders and values and the other one is the one that saves your data
You could also just make another script entirely that teleports your player
I guess this is my only option. And think the idea of just making 2 scripts would be much better because it would make everything clearer. Thanks for your help and your time
No problem
Glad I could help out!
Good luck on your datastore & your game
Update after rewriting the Scripting and splitting it into 2 Scripts: IT WORKS NOW
I still don’t know what the problem with the original Script was but that doesn’t matter now.
Again, THANK YOU FOR YOUR HELP
No problem!
Glad it all worked out