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

Am I doing DataStore right?

Asked by 9 years ago

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)
0
No, no you aren't. You're Welcome. Vezious 310 — 9y
0
.Thanks..I guess? ISellCows 2 — 9y
0
Btw can I buy one of the cows your selling? Vezious 310 — 9y
0
No.. ISellCows 2 — 9y

1 answer

Log in to vote
3
Answered by 9 years ago

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!

0
Thanks. ;D ISellCows 2 — 9y
Ad

Answer this question