I'm making a data-store for my game "Salutations", and i wanted to save multiple things. However it's not really saving the data.
I have Cash; [IntValue], and i have Quest; [NumberValue]
It's not saving them, and i have no errors for reference.
Here's the script;
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = leaderstats
local Quest = Instance.new("NumberValue")
Quest.Name = "Quest"
Quest.Parent = leaderstats
local PlayerUserId = "Player_"..player.UserId
local data
local sucess, errormessage = pcall(function()
local data = myDataStore:GetAsync(PlayerUserId)
end)
if sucess then
if data then
Quest.Value = data
Cash.Value = data
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local PlayerUserId = "Player_"..player.UserId
local data = {
Cash = player.leaderstats.Cash.Value;
Quest = player.leaderstats.Quest.Value;
}
local sucess, errormessage = pcall(function()
myDataStore:SetAsync(PlayerUserId, data)
end)
if sucess then
print("The Data Saved succesfully!")
else
print("The data did not save")
warn(errormessage)
end
end)
