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

Am I doing DataStore right?

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)

4 comments

0

No, no you aren't. You're Welcome.

0

.Thanks..I guess?

0

Btw can I buy one of the cows your selling?

0

No..

1 answer

✓ Accepted answer

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!

1 comment

0

Thanks. ;D

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