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

Help with DataStore?

Asked by 8 years ago

Can someone tell me why this DataStore script won't work?

Main code:

local player = script.Parent.Parent
local gui = player.PlayerGui:WaitForChild("Game")
local frame = gui:WaitForChild("Cash")
local stats = player:WaitForChild("leaderstats")
local cash = stats:WaitForChild("Cash")

local key = "Cash"..player.userId
local service = game:GetService("DataStoreService"):GetDataStore("GameService")

cash.Changed:connect(function()
    frame.Cash.Text = "Awarding cash..."
    service:SetAsync(key,cash.Value)
    print("Updated cash to "..cash.Value)
    wait(4)
    frame.Title.Cash.Text = "$0"..cash.Value
    print("Updated cash to "..cash.Value)
end)

Leaderboard code:

game.Players.PlayerAdded:connect(function(player)
    local cash = Instance.new("IntValue",player)
    cash.Name = "Cash"
    while wait(5) do
        cash.Value = cash.Value + 5
    end 
end)

1 answer

Log in to vote
0
Answered by 8 years ago

http://wiki.roblox.com/index.php?title=Data_store

Note: Data stores can only be accessed from server scripts.

It seems that you are trying to access Datastores from the client which will not work.

Ad

Answer this question