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 » Scripters
Home Search
 

Problem with datastores

Previous Thread :: Next Thread 
Matthais5 is not online. Matthais5
Joined: 19 Apr 2012
Total Posts: 6520
11 Jan 2016 06:09 PM
Long story short, I'm making a generic money system with DataStorage (so data persistence), but having some issues. Essentially, when a player joins I put an intValue in their player and add to it every so often. Here's that bit:

game.Players.PlayerAdded:connect(function(player)
local credits = Instance.new("IntValue")
credits.Name = "Credits"
credits.Value = 0
credits.Parent = player
end)
while wait(5) do
for _, player in ipairs(game.Players:GetPlayers()) do
if player:FindFirstChild("Credits") then
player.Credits.Value = player.Credits.Value + 10
end
end
end

Now I want it so that when a player clicks on a brick, their saved currency goes up by the value of "Credits" and set "Credits" to 0.

function onClicked(playerWhoClicked)
local key = "user_" .. playerWhoClicked.userId
DataStore:UpdateAsync(key, function(oldValue)
local newValue = oldValue or 0
newValue = newValue + playerWhoClicked.Credits.Value
playerWhoClicked.Credits.Value = 0
print(newValue)
return newValue
end)
end

game.Workspace.Part.ClickDetector.MouseClick:connect(onClicked)

This doesn't seem to work though.
Any help would be greatly appreciated :)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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