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

How to save a table in the datastore?

I have tried this but it didn't work.

Local script:

local weaponData =  --The table
{
    ironPick = false,
    silverPick = false,
    goldPick = false,
    diamondPick = false
}

local remote1 = game.ReplicatedStorage.DataStore
local buyBtn = script.Parent:WaitForChild("ScreenGui").Frame.TextButton

buyBtn.MouseButton1Click:Connect(function() --When the "Buy" Button is clicked we send the table to the Datastore server script

    remote1:FireServer(weaponData)

end)

Server Script:

local remote1 = game.ReplicatedStorage:WaitForChild("DataStore")
local ds = game:GetService("DataStoreService")
local ds1 = ds1:GetDataStore("pickData1Test")

remote1.OnServerEvent:Connect(function(player, weaponData)

    ds1:GetAsync(player.UserId, weaponData)

    ds1:SetAsync(player.UserId, weaponData)

    print("Data saved.")

end)

2 comments

0

Try finding player, in the local script using game.Players.LocalPlayer, then do remote1:FireServer(player, weaponData)

0

Also if that doesn't work, try and remove the player parameter on the OnServerEvent function

1 answer

✓ Accepted answer

You shouldn't be saving data with a RemoteEvent. You should only save data when the player leaves, when the game is going to shut down, after important events (i.e. when players make a purchase), and optionally every few minutes.

You don't need to save data every time a player purchases an item. Additionally, your remotes are insecure because they trust the client. Also, all player data should be packed into and saved with one table, not with a separate one for a weapon system.

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