Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is this line of code wont save your spot when you leave and rejoin and make you at start?

I was watching a tortorial and the scripts didnt work and i cant find new ones and im despreate. First i put the teams and make spawns that act like checkpoints. I add this scrpit in ServerScriptService.

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("ObbbyDataStore")

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()
		DataStoreService:SetAsync(player.UserId.."-stage",teamName)
	end)
	
	if success then
		print("All went well")
	else
		print(errorMessage)
	end
end)

And another script that has this code:

local checkpoints = game.Workspace:WaitForChild("Checkpoints"):GetChildren()

for i, checkpoint in pairs(checkpoints) do
	checkpoint.TeamColor = game.Teams:FindFirstChild(checkpoint.Name).Teamcolor
	checkpoint.BrickColor = game.Teams:FindFirstChild(checkpoint.Name).Teamcolor
end

1 answer

✓ Accepted answer

Watch the rest of AlvinBlox's video xD

1 comment

0

i got it lol

This discussion is preserved as it was. New answers, comments, and votes are closed.