Make sure to test it out in an actual client and not studio by the way
Studio sometimes breaks when testing data store
What part exactly?
Also shouldn’t I be fine if I just remove the CharacterAdded part because the big function is already connected to PlayerAdded
Im confused on what you mean by
Btw I just realized now the print from the Data saving prints too. It displays the right Value but when i spawn in the Stage Value in the Leaderboard gets set back to 0.
Yes you’re right I didn’t understand it was meant for teleporting the player to their current checkpoint I only skimmed through your code
Keep it as it is right now with CharacterAdded
I have one print after the GetAsync and one after the SetAsync because I tried troubleshooting the problem myself. Before you asked if the print shows something in the Output. And there I said the GetAsync one appears in the Output but the SetAsync one doesn’t, but later I realized it does show in the output. I just correct my statement from earlier.
local success, errormsg = pcall(function()
StageStore:SetAsync(player.UserId.."-Stage", {player.leaderstats.Stage.Value})
end)
try putting braces around player.leaderstats.Stage
Okay, what does that change (I would like to learn more, that’s why I am asking)?
Okay I changed it, it still doesn’t work, but it changed the Output i get.
00:49:40.508 Data loaded. - Server - CheckPointScriptTest:24
00:49:40.508 ▼ {
[1] = 1
} Instance - Server - CheckPointScriptTest:25
00:49:56.367 Data saved. - Server
00:49:56.367 ▼ {
[1] = 1
} Instance - Server
They’re basically a table and store data.
If you want to read more about it go here:
Did my solution work?
Ok interesting
Make sure you test it in client too please
What appears to be happening is that it is loading your data and that number in brackets should be the stage you are currently on.
Did you test it in the actual roblox client too?
I tried in the Client too and its still getting set back to 0.
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.