DataStore Working in Studio but not In-game

The datastore works fine in studio, but in game it just saves it everytime the game restarts.

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("Omaygawd3")
local Remote = game.ReplicatedStorage.RemoteFunction

function GetFingerPrintAsync(player)
	local Fingerprint = Remote:InvokeClient(player)
	return Fingerprint
end

game.Players.PlayerAdded:Connect(function(player)
	wait(3)
	local FingerPrint = GetFingerPrintAsync(player)
	local FPDatabase = ds:GetAsync(FingerPrint) 
	local Tag = game.Players:FindFirstChild(player.Name):AddTag(FingerPrint)
	if FPDatabase then
		if table.find(FPDatabase,player.Name) then
			print(FingerPrint)
			player:Kick("Already found in database, alts :\n"..table.unpack(FPDatabase))
		else
			print(FingerPrint)
			table.insert(FPDatabase,player.Name)
			ds:SetAsync(FingerPrint, FPDatabase)
		end
	else
		print(FingerPrint)
		ds:SetAsync(FingerPrint, {player.Name})

	end
	
end) 

2 Likes

Maybe use a bindtoclose.

game:BindToClose(function()
  task.wait(1)
end

1 Like

Used a bind to close but it did not save.

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("Omaygawd3")
local Remote = game.ReplicatedStorage.RemoteFunction

function GetFingerPrintAsync(player)
	local Fingerprint = Remote:InvokeClient(player)
	return Fingerprint
end

game.Players.PlayerAdded:Connect(function(player)

	local FingerPrint = GetFingerPrintAsync(player)
	local FPDatabase = ds:GetAsync(FingerPrint) 
	local Tag = game.Players:FindFirstChild(player.Name):AddTag(FingerPrint)

	if FPDatabase then
		if table.find(FPDatabase,player.Name) then
			player:Kick(table.unpack(FPDatabase))
		end
	end
	game:BindToClose(function()
		task.wait(1)
		if FPDatabase then
			if table.find(FPDatabase,player.Name) then
			else
				table.insert(FPDatabase,player.Name)
				ds:SetAsync(FingerPrint, FPDatabase)
			end
		else
			ds:SetAsync(FingerPrint, {player.Name})
		end
	end)

end)
	

--[[\
if FPDatabase then
		if table.find(FPDatabase,player.Name) then
			player:Kick("Already found in database, alts :\n"..table.unpack(FPDatabase))
		else
			table.insert(FPDatabase,player.Name)
			ds:SetAsync(FingerPrint, FPDatabase)
		end
	end
--]]
2 Likes