Suphi's DataStore Module

I think the same too however the.

function module.Add (player, key, amount)
	local dataStore = DataStoreModule.find("Player", player.UserId)
	if dataStore == nil then return end
	if dataStore.State ~= true then return end
	dataStore.Value[key] += amount
	dataStore.Resources[key].Value = dataStore.Value[key]
end

won’t work if the data didn’t have any value in it, however I think that would work because if didn’t have any value or it is their first time then the template would give a value from the template script like

local template = {
Level = 0,
}

I also edited the function to check if there is a value of 0 or nil

function module.Add (player, key, amount)
	local dataStore = DataStoreModule.find("Player", player.UserId)
	if dataStore == nil then return end
	if dataStore.State ~= true then return end
	if dataStore.Value[key] == 0 or nil then
		dataStore.Value[key] = amount
	else
		dataStore.Value[key] += amount
	end
	dataStore.Resources[key].Value = dataStore.Value[key]
end

But it still didn’t work, what I did to solve that problem from the time being is by using this function first to give a default value before changing any data.

function module.Set (player, key, value)
	local dataStore = DataStoreModule.find("Player", player.UserId)
	if dataStore == nil then return end
	if dataStore.State ~= true then return end
	dataStore.Value[key] = value
	dataStore.Resources[key].Value = value
end

Btw what is the use of the value in a template if it didn’t put a default value sir?
also the print from PlayerAdded in template script didn’t print either.

game.Players.PlayerAdded:Connect(function(player)
	local dataStore = DataStoreModule.new("Player", player.UserId)
	if dataStore:Open(template) ~= "Success" then print(player.Name, "failed to open") --didn't print this
	elseif dataStore:Open(template) == "Success" then print(player.Name, "Datastore was opened") nor this one.
	print(dataStore.State)
end