Is their a way to check if a player has already joined your game?
without using badges?
Is their a way to check if a player has already joined your game?
without using badges?
You could use datastores. Save the player into a datastore when they join the game, you can just check whether the player exists in the datastore to determine whether its their first time or not.
Do you know what type of data store I should use?
Global Datastore, the one people use commonly
local DataStoreService = game:GetService("DataStoreService")
local DS = DatsStoreService:GetDataStore("PlayerJoinData")
game.Players.PlayerAdded:Connect(function(player)
local Data
local success, err = pcall(function()
Data = DS:GetAsync(player.UserId)
end)
if not success then
print(err)
Player:Kick("Error while loading Data")
end
if Data then
PlayerJoined before
else
DS:SetAsync(player.UserId, true)
end
end)
but where would it save and how could you see it
Hi!
local DataStoreService = game:GetService("DataStoreService")
local DS = DatsStoreService:GetDataStore("PlayerJoinData")
game.Players.PlayerAdded:Connect(function(player)
local Data
local success, err = pcall(function()
Data = DS:GetAsync(player.UserId) -- It will get data here if any is found
end)
if not success then
print(err)
Player:Kick("Error while loading Data")
end
if Data then -- If we found data, then the player has joined the game before
PlayerJoined before
else
DS:SetAsync(player.UserId, true) -- It will set & save the datastoreUniqueKey's data here to be true. The datastoreUniqueKey will be the Player.Userid (which is also a unique key, just for roblox users)
end
end)
Oh sorry, I meant how you could see datastore I’m saying? say as they leave and you leave well then that server doesn’t exist anymore until you join again and it makes a new server that reset everything unless the datastore editor plugin?
srry I’m new to scripting
DataStore saves within the game, and not the server.
So if the server shuts down, and they join in a new server, then the server will still know that they’ve joined the game before.
oh i see what you mean, what about the dev console that has text in there could that save to your saying
What would you like to save? It all depends on what you try to save.
lets just saaay a print like in the dev console it would say (“Print”) could that save inside the dev console?
Why would you like to save that?
it was just an example, im srry but if it ever errors or not but it save wouldn’t it say the info inside the dev console or something else
I would suggest that you look into DataStore2. DataStore2 makes it easier for new scripters to handle Data. DataStore2 is a script, made by another scripter. Here you can read more about DataStore2: How to use DataStore2 - Data Store caching and data loss prevention
Hmmm ok ill look into this thx
Just put script in ServerScriptService.
local DataStoreService = game:GetService("DataStoreService")
local DS = DatsStoreService:GetDataStore("PlayerJoinData")
game.Players.PlayerAdded:Connect(function(player)
local Data
local success, err = pcall(function()
Data = DS:GetAsync(player.UserId)
end)
if not success then
print(err)
Player:Kick("Error while loading Data")
end
if Data then
--PlayerJoined before
else
DS:SetAsync(player.UserId, true)
end
end)
All will work correctly.
Can you explain more of the script?
local DataStoreService = game:GetService("DataStoreService") -- Getting DataStoreService
local DS = DatsStoreService:GetDataStore("PlayerJoinData") -- Make new DataStore called 'PlayerJoinData'
game.Players.PlayerAdded:Connect(function(player) -- Run this if player join
local Data -- making data variable.
local success, err = pcall(function() -- A function that allows the script to continue running even if an error occurs
Data = DS:GetAsync(player.UserId) -- So we have to get data with player's UserId.
end)
if not success then -- If we got problem durinng loading data.
print(err) -- print error message
Player:Kick("Error while loading Data") -- kick player
end
if Data then -- But if we have data that mean player joined before
--PlayerJoined before
else -- If dont have data.
-- New player
DS:SetAsync(player.UserId, true) -- We set data to new player
end
end)
Hey! I made an explanation video. Some of the details for the analogy don’t quite match up, but the concepts remain the same. If you need further explanation, let me know!
Helpful resources!
https://developer.roblox.com/en-us/api-reference/class/DataStoreService
https://developer.roblox.com/en-us/api-reference/function/GlobalDataStore/GetAsync
https://developer.roblox.com/en-us/api-reference/function/GlobalDataStore/SetAsync