Hi. I'm making a mining game and here, I want to add money for every block mined and I want to add 1 to the players blocks mined. I used datastore 2 for this to handle the data stuff When the user breaks a block with a pickaxe it uses a remote function to break the block so I tried to add the values to money and blocks mined in there but when I do this I get the error "attempt to index number with 'BlocksMined' "
They are both server scripts.
This is the script that handles the datastore stuff
local DataStore2 = require(1936396537)
DataStore2.Combine("Money","BlocksMined")
local defaultMoney = 0
local defualtBlocks = 0
game.Players.PlayerAdded:Connect(function(player)
--leaderstats
local leaderstats = Instance.new("Folder", player); leaderstats.Name = "leaderstats"
local moneyValue = Instance.new("IntValue", leaderstats); moneyValue.Name = "Money"
local blocksValue = Instance.new("IntValue", leaderstats); blocksValue.Name = "BlocksMined"
--get datastores
local moneyStore = DataStore2("Money", player)
local blocksStore = DataStore2("BlocksMined", player)
local function updateMoney(money)
player.leaderstats.Money.Value = money
end
local function updateBlocks(blocks)
player.leaderstats.BlocksMined.Value = blocks
end
--call function right away one time
updateMoney(moneyStore:Get(defaultMoney))
updateBlocks(blocksStore:Get(defualtBlocks))
--call functions again on updates
moneyStore:OnUpdate(updateMoney)
blocksStore:OnUpdate(updateBlocks)
end)
and this is the script that handles blocks being destroyed
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteFunction = ReplicatedStorage:WaitForChild("RemoteFunctionBreakBlock")
local DataStore2 = require(1936396537)
local function destroyPart(player, target)
local blocksStore = DataStore2("BlocksMined",player)
local moneyStore = DataStore2("Money",player)
target:Destroy()
moneyStore:Increment(5)
blocksStore:Increment(1)
return target
end
remoteFunction.OnServerInvoke = destroyPart
Any ideas why it doesn't work?
