I've made (with the help of some videos) a DataStore script, and it was supposed to work but it didn't. Here's the script :
local DSService = game:GetService("DataStoreService")
local playerCoins = DSService:GetDataStore("plrCoins")
game.Players.PlayerAdded:connect(function(player)
local playerId = "player_"..player.userId
local coins = Instance.new("IntValue", game.Workspace.Stats) -- the value is stored inside a Folder in game.Workspace
local GetCoins = playerCoins:GetAsync(playerId) -- is supposed to get the value stored in the DataStoreService
coins.Value = GetCoins[playerId] or 0 -- Error at this line. Should set coins' value to the one stored (or to 0 if nothing is found)
playerCoins:SetAsync(playerId, coins.Value) -- Update the value of coins inside the DataStoreService
end)
The error is : "ServerScriptService.Script:9:Attempt to index local 'GetCoins' (a number value)"
I think it has something to do with tables but i'm not sure, i didn't really understand, so could someone explain me please ? Just to mention, sometimes, it works and some other times it just shows this error when running the game on Roblox Studio

1 comment
Put the folder inside the player and keep it in a local script.