Data saved value, but when retrieving it's got nil

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m making Data Store Module.
  2. What is the issue? Include screenshots / videos if possible!
    The issue is, data saved the value, but when retrieving it’s said the key i retrieved is nil. Even my spelling is corrected. When tested in console command, it show data. But when called from script, it show nil.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Found 3 post, but the post isn’t solved yet.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Module Script:
local DataStoreService = game:GetService("DataStoreService")
local MainData = DataStoreService:GetDataStore("Hello")
function datamethod:Get(key) 
	assert(MainData ~= nil, "You did not set up data store.")
	assert(key ~= "", "Please consider inputting key in order getting value by key.")
	assert(typeof(key) ~= nil, "You can't retrieve nil.")
	
	local success
	local err
	
	local repeatedcount = 0
	
	local data
	
	status.onGet = true
	
	repeat
		repeatedcount += 1
    success, err = pcall(function()
		data = MainData:GetAsync(key)
		end)
		until repeatedcount >= 3 or success
	if success and data then
		status.onGet = false
		return data	
	elseif success and not data then
		status.onGet = false
		return nil
	else
		status.onGet = false
		return "error"
	end
end

function datamethod:Set(key, value)
	assert(MainData ~= nil, "You did not set up data store.")
	assert(key ~= "", "Please consider inputting key in order setting value by key.")
	assert(typeof(value) ~= "Instance", "You can't store instance inside of datastore, invalid UTF - 8 characters.") 
	   assert(typeof(value) ~= "nil", "You cannot store nil value inside datastores.")
	assert(typeof(key) ~= "nil", "You cannot set key a nil.")
	local success
	local err
	
	
	local repeatedcount = 0
	
	status.onSet = true
	
	repeat
		repeatedcount = repeatedcount + 1
	 success, err = pcall(function()
		MainData:SetAsync(key, value)
	end)
		    
	until repeatedcount >= 3 or success	
		
	if success then
		status.onSet = false
		return "success"
		
	else
		status.onSet = false
		return "error"
	end
end
-- I do use updateasync() method.
Server Script:
game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	
	local value = Instance.new("IntValue")
	value.Name = "Cash"
	value.Value = 0
	value.Parent = leaderstats
	
	
	local data = DSM:Get(plr.UserId)
	if data then
		value.Value = data
		leaderstats.Parent = plr
		
	else
		value.Value = 0
		leaderstats.Parent = plr
		
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local stat = plr.leaderstats:WaitForChild("Cash")
	if stat then
		DSM:Set(plr.UserId, stat.Value)
	end
end)

It print (“Saved”) everytime I trying saving data, but when retrieving. It said nil. When tested it with command bar, it show data.

Nevermind, I know what caused this.

[ It’s because I forgot to use return method…, that’s why it return nil. ]

If you answer your own question please provide your solution to help anyone that may find this thread in the future.