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