I am new to DataStore
, I've read the wiki and a few example script's but I am not sure if I am using DataStore
right, can someone tell me if I am and if I'm not can you tell me what I am doing wrong about it?
wait(1) local player = game.Players.LocalPlayer local stats = player:WaitForChild("leaderstats") local cash = stats:WaitForChild("Cash") local service = game:GetService("DataStoreService"):GetDataStore("GameValues") cash.Changed:connect(function() service:SetAsync("Cash",cash.Value) print("Updated cash to "..cash.Value) end)
1. It's because you have to use a key. Like, for example
local key = "Playerkey"..player.userID
Each key has to be different so you can access the datastore, i believe.
So basically, you have to do
service:SetAsync(key,cash.Value)
2. Guessing by local player = game.Players.LocalPlayer, It's a Localscript.
You can't use DataStoreService in a localscript, only in a serverscript.
If you have any questions, i'll be happy to reply!