generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Storing cash using DataStore

Previous Thread :: Next Thread 
MasterDaniel is not online. MasterDaniel
Joined: 28 Nov 2008
Total Posts: 2866
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
MasterDaniel is not online. MasterDaniel
Joined: 28 Nov 2008
Total Posts: 2866
16 Apr 2014 01:33 PM
Anyone?...
Report Abuse
MasterDaniel is not online. MasterDaniel
Joined: 28 Nov 2008
Total Posts: 2866
17 Apr 2014 11:00 AM
Is there anyone out there? :p
Report Abuse
MasterDaniel is not online. MasterDaniel
Joined: 28 Nov 2008
Total Posts: 2866
21 Apr 2014 06:33 AM
4 days later... :p
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image