Datastore not saving after proximity prompt trigger

code:

local DataStoreService = game:GetService("DataStoreService")
local goldStore = DataStoreService:GetDataStore("Save")

script.Parent.Triggered:Connect(function(plr)
	script.Parent.Parent.Parent.Click:Play()

	-- Data store key and value
	local playerUserID = plr.UserId
	local SaveHunger = game.Workspace.PLAYER["Floppa cube"].Hunger.TextLabel.Hunger
	local SaveAge = game.Workspace.PLAYER["Floppa cube"].Age.TextLabel.Number
	local SaveMoney = plr.PlayerGui.Money.TextLabel.Value

	-- Set data store key
	local setSuccess, errorMessage = pcall(function()
		goldStore:SetAsync(playerUserID, SaveHunger.Value)
		goldStore:SetAsync(playerUserID, SaveAge.Value)
		goldStore:SetAsync(playerUserID, SaveMoney.Value)
	end)
	if not setSuccess then
		warn(errorMessage)
	end
	
	local getSuccess, currenthunger, currentage, currentmoney = pcall(function()
		return goldStore:GetAsync(playerUserID)
	end)
	if getSuccess then
		print(currenthunger..currentage..currentmoney)
	end
end)

game.Workspace["Delete Save"]["Floppy Disk"].Part.ProximityPrompt.Triggered:Connect(function(plr)
	local getSuccess, currenthunger, currentage, currentmoney = pcall(function()
		return goldStore:RemoveAsync(plr.UserId)
	end)
	if getSuccess then
		print(currenthunger..currentage..currentmoney)
	end
end)

datastore not saving after proximity prompt trigger

any help will work

you override the data here, means only SaveMoney.Value saves
you should pack these inside table

goldStore:SetAsync(playerUserID, {
	Hunger = SaveHunger.Value, 
	Age = SaveAge.Value, 
	Money = SaveMoney.Value
})
local getSuccess, Value, Info = pcall(function()
	return goldStore:GetAsync(playerUserID)
end)
if getSuccess then
	print("Hunger: ", Value.Hunger , "\nAge: ", Value.Age, "\nMoney: ", Value.Money)
end
3 Likes