Way to check if player has ever played game using a DataStore?

Is there a way to check if a player has EVER loaded into the experience, whether it was 1 minute ago or 1 year ago, or any other time frame. I know this would use DataStores because it could store userId. I don’t really know how to go, but I do know to create a DataStore and get the DSS (DataStoreService)

So far I have this, but I don’t no where to go from here:

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

game.Players.PlayerAdded:Connect(function()
	local data 
end)

the data variable I created equals the key, which is used to check data.

its actually very simple u can create a int value when the player joins the game add one +1 to the value and save it with dataStore, and when u want to check if the player has ever joined the game:

if value.value >= 2 then
– the player joined the game twice or more
else
– the player join at least 1 time
end

How would I save the int value though? Additionally, where would the int be located, this script is in ServerScriptService

here is a full tutorial for beginners on how to use datastore: Roblox DataStore Tutorial - Data Stores & Saving Data - Scripting Tutorial - YouTube

I have a script that saves teams, so can I modify it to save an int value, like @THEWOLF5555555 said?

Script:

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")
		print(data) 
	end)
	if success then
		print("Success, loaded ObbyDataStore")
		if data then
			player.Team = game.Teams[data]
		else
			player.Team = game.Teams.Stage1
		end
	else
		print(errorMessage)
		player.Team = game.Teams.Stage1
	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("Saved data succesfully")
	else
		print(errorMessage)
	end
end)
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local DataStore = DataStoreService:GetDataStore("PlayedJoinedCheck")

Players.PlayerAdded:Connect(function(player)
	local Data 
	--get their datastore value(may fail if datastores are down)
	local Success, Error = pcall(function()
		Data = DataStore:GetAsync(player.UserId)
	end)
	if Success then 
		if Data then
			print(player.Name.." has joined on the past") 
		else 
			print(player.Name.." joined for the first time")
			--set their datastore value(may fail if datastores are down)
			pcall(function()
				DataStore:SetAsync(player.UserId, true)
			end)
		end
	else 
		warn("Failed to load "..player.Name.." data("..Error..")")
	end
end)
2 Likes

I still need to get DSS, right?

What do you mean by that? You have to get their data to check if they have joined the game before.

DSS refers to DataStoreService, but it did work. Thank you, I find this super helpful, for a few reasons! <3

Merry christmas and/or Happy Holidays!

3 Likes