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

Detect when a player first joins with datastores?

Server script:

local DSS = game:GetService("DataStoreService")
local Tutorial = DSS:GetDataStore("Tutorial")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		local tpopup = Instance.new("BoolValue")
		tpopup.Name = "FirstTime"
		tpopup.Parent = player
		tpopup.Value = Tutorial:GetAsync(player.userId) or true

		if player:WaitForChild("FirstTime").Value == true then
			game.ReplicatedStorage.TutorialPopup:FireClient()

		game.Players.PlayerRemoving:connect(function(Player)
			Tutorial:SetAsync(player.userId, tpopup.Value)
		end)
	end)
end)

Local script:

game.ReplicatedStorage.TutorialPopup.OnClientEvent:Connect(function(player)
	--code here for tutorial
	player:WaitForChild("FirstTime").Value = false
end)

These two scripts, for some reason, don't work. I've tried printing the local player's name when the event is fired but nothing happens in output. I want it so when a new player first joins, load in their data or set it to true if they don't have data (are new). If true then fire a event to the player's client for the tutorial, etc etc.

1 answer

In the serverscript, you have to check if Tutorial:GetAsync() is nil, and if it is, load the Tutorial.

2 comments

0

This didn't work

0

How did you test it? Did you use another Datastore?

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