I’m trying to make data store for my obby game so that when a player lands on a checkpoint and leave the game, they rejoin on the same checkpoint they landed on before leaving.
I can’t figure out what I did wrong so that my code doesn’t save the data like how it should, when I join and get to a checkpoint then leave to rejoin, it just spawns me right back to the first stage and I still lose my progress. I’m following this scripting tutorial by AlvinBlox - Saving Obby Checkpoints - Roblox Scripting Tutorial - YouTube
I’ve rechecked my code countless times and tried to use the free Data Editor plugin but the plugin wont work while in the game and my code won’t work either even though I’ve skimmed through it and it seems to be identical to AlvinBlox’s code.
Here’s my code.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("ObbyDataStore")
game.Players.PlayerAdded:Connect(function(player)
local data
local success, errorMessage = pcall (function()
data = DataStore:GetAsync(player.UserId.."-stage,")
end)
if success then
print("Success")
if data then
player.Team = game.Teams[data]
else
player.Team = game.Teams.Stage1
end
else
player.Team = game.Teams.Stage1
end
player:LoadCharacter()
end)
game.Players.PlayerRemoving:Connect(function(player)
local teamName = player.Team.Name
local success, errorMessage = pcall (function()
DataStore:SetAsync(player.UserId.."-stage,teamName")
end)
if success then
print("All went well")
else
print(errorMessage)
end
end)