|
| 16 Apr 2014 09:12 AM |
I tried to convert a previous DP script I had over to using DataStores. This is the result - it doesn't work and I'm not surprised with my level of skill. Anyone see the problem?
local DataStore = game:GetService("DataStoreService"):GetDataStore("Cash") local key = "user_" .. player.userId
function saveScore(player, score) SetAsync(key, score) end
function loadScore(player, clickCounter) local score = GetAsync(key) if score ~= 0 then clickCounter.Value = score else print("Nothing to load/score was 0") end end
function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local clicks = Instance.new("IntValue") clicks.Name = "Cash" clicks.Value = 0 clicks.Parent = stats stats.Parent = newPlayer loadScore(newPlayer, clicks) end
function onPlayerRemoving(player) print("Attempting to save score for " .. player.Name) local stats = player:FindFirstChild("leaderstats") if (stats ~= nil) then local clicks = stats:FindFirstChild("Cash") ----- Change to the currency if (clicks ~= nil) then saveScore(player, clicks.Value) DataStore:UpdateAsync(key, function(oldValue) local newValue = oldValue or 0 --oldValue might be nil newValue = clicks end) end end end |
|
|
| Report Abuse |
|
| |
|
| 17 Apr 2014 11:00 AM |
| Is there anyone out there? :p |
|
|
| Report Abuse |
|
| |