Player join system is not working

  1. What do you want to achieve? Keep it simple and clear!

Hello, so basically I am trying to make a new player join system

  1. What is the issue? Include screenshots / videos if possible!

when a new player joins the system will check their playergui if they have the “JoinBefore” Value that is stored in DataStore then the gui will not show. Otherwise when they finished or click on skip tutorial then the value will be created in their playergui. But the problem is when they left the game and the Value is being stored. The next day they come back and play the game they are on hold as new players.

local StringMsg = {"Hello, Welcome to Farmer Simulator! We have notice that you are new to the game!"}
local Datastore = game:GetService("DataStoreService"):GetDataStore("NewStore")
local NewPlr = Instance.new("IntValue")

game.Players.PlayerAdded:Connect(function(player)
	local NewPlayerGui = player.PlayerGui:WaitForChild("NewPlayer")
	local Frame = NewPlayerGui:WaitForChild("Frame")
	
	if Frame.Visible == false and Frame:FindFirstChild(NewPlr.Name) then
		NewPlayerGui.Name = "JoinBeforeValue"
		print(player.Name .. " Welcome back!")
	else
		NewPlayerGui.Name = "NewPlayerValue"
		Frame.TextLabel.Text = StringMsg[1]
		Frame.Visible = true
		print(player.Name .. " is new to the game!")
	end
	local Data
	local success, err = pcall(function()
		Data = Datastore:GetAsync(player.UserId, NewPlr.Value)
	end)
	if success then
		print(player.Name .. " data has been successfully loaded into the game!")
	else
		print(player.Name .. " Data was not successfully loaded!")
	end
	Frame:WaitForChild("TextButton").MouseButton1Click:Connect(function()
		Frame.Visible = false
		NewPlr.Parent = NewPlayerGui
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local su, re = pcall(function()
		Datastore:SetAsync(player.UserId, NewPlr.Value)
	end)
	if su then
		print(player.Name .. " left the game saving data..")
		warn("success! ~-~")
	else
		print("Warning:", string.upper(player.Name .. "left the game and the data was not saved successfully.. left the game and the data was not saved successfully.." .. re))
		warn("Failed :'(")
	end
end)

game:BindToClose(function()
	for _,v in pairs(game.Players:GetPlayers()) do	
		local su, re = pcall(function()
			Datastore:SetAsync(v.UserId, NewPlr.Value)
		end)
		if su then
			warn("Developer has shut down the game or something unexpectly happened while trying to save player data " .. su)
		else
			warn("Warning:", string.upper("Developer has shut down the game or something unexpectly happened while trying to save player data" .. re))
		end
	end
end)

I felt really bad that I kept on coming back and asking for help on Devforum… As to like I’m not a very good scripter.

It seems that the value is being checked before the data is loaded, also I’m a bit confused on why you would check if the player has joined before using a gui?

I’m still a bit of a new programmer myself and i’m not that familiar with datastores so if anyone wants to correct me then feel free to do so.

You should be using RemoteEvent instances for this and handling the DataStore saving/loading solely on the server and then the gui handling solely on the client. If the value of the value instance “NewPlr” is being set locally (by the client) then it won’t replicate to the server and as such, seen players (previous visitors) will still be incorrectly regarded as unseen players (new visitors).