Hello! So I’m trying to make a game Cald The Roblox Marathon which is supposed to be something like the impossible obby, but harder. Anyways, I made a Obby Saver, The Checkpoints/Spawn Points when you touch them, their supposed to save your spawn point so when you rejoin the game then you will be put back their. The issue is for some reason It can change my team but also when I rejoined the game then what happened was, It didn’t save my proggress at all and I was taken back to the Lobby.
local checkpoints = game.Workspace:WaitForChild("Checkpoints"):GetChildren()
-- ^ Returns a table containing all of the stage blocks
for i, checkpoint in pairs(checkpoints) do
-- Any code inside of here will repeat for each checkpoint
checkpoint.TeamColor = game.Teams:FindFirstChild(checkpoint.Name)
end
PlayerTeam
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("ObbyLevelData")
game.Players.PlayerAdded:Connect(function(player)
local data
local success, errorMessage = pcall(function()
data = DataStore.GetAsync(player.UserId.."-Stage")
end)
if success then
if data then
player.Team = game.Teams[data]
else
player.Team = game.Teams.Lobby
end
else
player.Team = game.Teams.Lobby
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local teamName = player.Team
local success, errorMessage = pcall(function()
DataStore.SetAsync(player.UserId.."-Stage",teamName)
end)
if success then
print("Player Data Successfuly Saved!")
else
warn(errorMessage)
end
end)
Get the TeamColor of the found Team. (I don’t remember the property name exactly)
local checkpoints = game.Workspace:WaitForChild("Checkpoints"):GetChildren()
-- ^ Returns a table containing all of the stage blocks
for i, checkpoint in pairs(checkpoints) do
-- Any code inside of here will repeat for each checkpoint
local team = game.Teams:FindFirstChild(checkpoint.Name)
if team then
checkpoint.TeamColor = team.TeamColor
end
end
You cannot store Object values (which Player.Team is) into Datastores.
What you can actually do is just get the Team’s name and save it, then load it and find a Team with that name. You will get an error if you add 'print(errorMessage)' to the PlayerAdded function.
So the code should look something like this:
Save:
local teamName = player.Team.Name
local success, errorMessage = pcall(function()
DataStore.SetAsync(player.UserId.."-Stage",teamName)
end)
if success then
print("Player Data Successfuly Saved!")
else
warn(errorMessage)
end
Load:
local data
local success, errorMessage = pcall(function()
data = DataStore.GetAsync(player.UserId.."-Stage")
end)
if success then
if data then
player.Team = game.Teams:FindFirstChild(data)
else
player.Team = game.Teams.Lobby
end
else
player.Team = game.Teams.Lobby
end
Reply if this doesn’t work or you have any questions (Sorry for any typos!)
09:52:20.357 ServerScriptService.PlayerTeam:39: Expected 'end' (to close 'function' at line 27), got <eof>; did you forget to close 'function' at line 31? - Studio - PlayerTeam:39
What I changed
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("ObbyLevelData")
game.Players.PlayerAdded:Connect(function(player)
local data
local success, errorMessage = pcall(function()
data = DataStore.GetAsync(player.UserId.."-Stage")
end)
if success then
if data then
player.Team = game.Teams:FindFirstChild(data)
else
player.Team = game.Teams.Lobby
end
else
player.Team = game.Teams.Lobby
end
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("Player Data Successfuly Saved!")
else
warn(errorMessage)
end