Welcome all to the third part of our Community Resource series, here we are making a script that will detect if a player has joined before. Sorry for not posting for a long time.
Resource Number 3
|
Detect If Player Has Joined Before Logic
local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerJoinData")
game.Players.PlayerAdded:Connect(function(player)
local playerKey = "Player_" .. player.UserId
local success, data = pcall(function()
return playerDataStore:GetAsync(playerKey)
end)
if success then
if data == nil then
-- Player is joining for the first time
print(player.Name .. " is joining for the first time!")
-- Save the player's first join status
pcall(function()
playerDataStore:SetAsync(playerKey, true)
end)
else
-- Player has joined before
print(player.Name .. " has joined before.")
end
else
-- Handle DataStore error
warn("Could not access DataStore for " .. player.Name)
end
end)
Short Video Representation
|
Click Here - Streamable
On Your End
-
Create a
Script
and put in inside ofServerScriptService
and name theScript
however you’d like -
Copy the code above and paste it inside of the
Script
Other Resources
Community Resource 1
Community Resource 2
These scripts are some of the data that will be used in the development of our game, use them as you please, no credit is needed. Come back next time! Thank you!