Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is the Datastore not save? (im confused)

Asked by 5 years ago

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

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

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

Ad

Answer this question