Hello developers,
Im having problems with my module script where it sets your data and gets your data. But my problem is, when getting the data. it returns nil. I’m not sure if the problem is on :Set
module or :Get
module. Thanks for helping out with my problem, i appreciate it!
Script:
function ChatBot.Data:Set(DataName,playerr,Key,GroupName,DataNames)
local SetData = DataStoreService:GetDataStore(DataName)
playerr = game.Players:FindFirstChild(playerr)
if playerr then
local key = tostring(playerr.UserId)..Key
local valuess = {}
for __,__value in pairs(playerr:FindFirstChild(GroupName):GetChildren()) do
table.insert(valuess, __value.Value)
end
SetData:SetAsync(key,valuess)
end
end
function ChatBot.Data:Get(DataName,player,Key)
local GetData = DataStoreService:GetDataStore(DataName)
local key = tostring(player.UserId)..Key
local UsedData = GetData:GetAsync(key)
if UsedData then
return UsedData
else
--error("The user haven't created a data yet! Try using .Data:Set to create a data for the user!")
return UsedData -- returns nil :(
end
end