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

Will this work to signify if a player has been in the game before?

If they haven't been in the game before, this will set it to true, but something else needs to happen if they haven't, my intro GUI handled by a separate localscript. How exactly would I get this to work? I'm sort of being braindead at the moment and confused. Help, please?

local player = script.Parent.Parent.Parent.Parent
local datastoreservice = game:GetService("DataStoreService"):GetDataStore("BoE_BeenBefore")
local beenbefore


game.Players.PlayerAdded:connect(function()
	if datastoreservice:GetAsync(player.userId) == false or nil then
		script.Parent.beenbefore.Value = false
		datastoreservice:SetAsync(player.userId,true)
	elseif datastoreservice:GetAsync(player.userId) == true then
		script.Parent.beenbefore.Value = true
	end
end)

1 answer

Couple of things:

  • The key must not be the player's userId
  • You must either set or update async to set it.

#Key The key of a datastore must not be the player's userId; plain. So you can add a "player_" or "user_" in front of the id. Also, make sure the userId is greater than 0, this means the player is a guest.

if plyr.userId > 0 then
	DS:SetAsync("user_"..plyr.userId, 173821)
end

#UpdateAsync(string Key, Variant function(Variant) transformFunction) Updates the async.

DS:UpdateAsync("user_"..plyr.userId, function()
	return true --return the value you want it to change to.
end)

#SetAsync(string Key, Variant value) SetAsync is like GetAsync but there is another argument, the value you are setting it to.

DS:SetAsync("user_"..plyr.userId, 173821)


#Final Product

local datastoreservice = game:GetService("DataStoreService"):GetDataStore("BoE_BeenBefore")

game.Players.PlayerAdded:connect(function(player) --You didn't need line 1, just do this instead.
	if datastoreservice:GetAsync("user_"..player.userId) == nil then
		datastoreservice:SetAsync("user_"..player.userId, false)
	elseif datastoreservice:GetAsync("user_"..player.userId) == false then
		datastoreservice:SetAsync("user_"..player.userId, true)
	end
end)


Hope it helps!

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