i cant figure out what.I should have spawned in spawn1 but I spawn in spawn2 and the code that is meant to save data to datastore doesn't save it.plz help me.
Here is the 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
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 = game.player.Team.Name
local success, errorMessage = pcall(function()
DataStore:SetAsync(player.UserId.."-stage",TeamName)
end)
end)
Plz help me fix it.

2 comments
ohh now i get it
Please indent your code properly