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)
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.