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)
