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

On join, if no data, set data to 0?

How do you make it so when a player joins, it checks if he has DataStore and if no, create the data by setting it to 1? (And will the server be able to read a data that is 0?)

1 answer

✓ Accepted answer

You don't need to check if the player has joined before, you just have to check if the player has said DataStore.

local DDS = game:GetService("DataStoreService")
local dataStore = DDS:GetDataStore("joinedBefore")

game.Players.PlayerAdded:connect(function(plr)
	local s,f = pcall(function()
		ds = dataStore:GetAsync(plr.UserId)
	end)
	if s and ds then
		print(ds)
	else
		print("no ds, creating a new one")
		pcall(function()
			dataStore:SetASync(plr.UserId, "info")
		end)
	end
end)

3 comments

0

If you need any more help, don't hesitate to contact me!

0

It always say that there is no data?

0

Nevermind! Thanks

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