Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is the Datastore not save? (im confused)

Script

local DataStoreService = game:GetService("DataStoreService")
local currentPackStore = DataStoreService:GetDataStore("CurrentPack")
local repS = game:GetService("ReplicatedStorage")
local updateRemote = repS:FindFirstChild("DataStore")

game.Players.PlayerAdded:Connect(function(player)

local success, err = pcall(function()
	currentPackStore:SetAsync(player, "Animation_Default")
end)
 
if success then
	print("[Character System]: Load Successful!")
end

local success, currentAnimPack = pcall(function()
	return currentPackStore:GetAsync(player)
end)
 
if success then
	print("[Character System]: Current Pack is ", currentAnimPack)
end

end)


updateRemote.OnServerEvent:Connect(function(pplayer,Pack)

local success, newPack = pcall(function()
	return currentPackStore:UpdateAsync(pplayer, Pack)
end)
 
if success then
	print("[Character System]: Save Successful! New Pack is ", newPack)
end
end)

Localscript

local repS = game:GetService("ReplicatedStorage")
local updateRemote = repS:FindFirstChild("DataStore")

script.Parent.TextButton.MouseButton1Click:Connect(function()
	updateRemote:FireServer(script.Parent.TextBox.Text)
end)

so , when i press the button with a text or any String , it should print that its saved , but it doesnt do that for some reason :/

1 answer

✓ Accepted answer

This isn't how you should use UpdateAsync() (line 30) The second argument of it should be a function, which returns the table/string/number that you want to save.

Example:

DataStore:UpdateAsync(key, function(data)
	data.Coins = data.Coins + 100
	return data
end)

Although in your case, the most suitable solution would be to use SetAsync() rather than UpdateAsync(), just like you did on line 9.

So just replace UpdateAsync with SaveAsync in your code

This discussion is preserved as it was. New answers, comments, and votes are closed.