Hi I'm making a mining game. Right now I'm trying to let users mine ores and then sell them. I've been able to achieve most of it except my script to sell your ores doesn't work. I'm pretty new to lua scripting on roblox so any help would be greatly appreciated.
So how it's currently set up is I have a Remote event for each ore, for currency and for selling ores. I have gui that displays how much of each ore you have and how much money you have. I don't know if there's a better way to do this but I've got a server script for each ore to handle this as well.
Here's an example of one of the ore's server scripts
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local DataStore2 = require(1936396537)
local defualtCoalAmount = 0
players.PlayerAdded:Connect(function(player)
local CoalStore = DataStore2("Coal", player)
local function updateClientCoal(amount)
replicatedStorage.RemoteEvents.UpdateClientCoal:FireClient(player,amount)
end
updateClientCoal(CoalStore:Get(defualtCoalAmount))
CoalStore:OnUpdate(updateClientCoal)
end)
Here's one of the local scripts from the gui
local replicatedStorage = game:GetService("ReplicatedStorage")
replicatedStorage.RemoteEvents.UpdateClientCoal.OnClientEvent:Connect(function(amount)
script.Parent.Text = amount
game.Workspace.CoalVal.Value = amount
end)
The script to mine ore looks like this. It's a basic version of what I want to do but all that happens is when you click on a ore it adds one to the amount of the ore you have
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local DataStore2 = require(1936396537)
local function onMouseClick(player)
for k, v in pairs(players:GetChildren()) do
local CoalStore = DataStore2("Coal", v)
CoalStore:Increment(1)
end
end
script.parent.ClickDetector.MouseClick:connect(onMouseClick)
And then selling the ores, which is what I'm stuck on, is this. There's a block and when you click it I'm trying to get it to add the amount of whatever ore you have * a certain number to the currency. I have a local script in the block to detect clicks and then a server script to add money etc
local script
local repstorage = game:GetService("ReplicatedStorage")
local clickdetector = script.parent.ClickDetector
function onMouseClick()
print("Click Detected")
repstorage.RemoteEvents.SellOre:FireServer()
end
clickdetector.MouseClick:Connect(onMouseClick)
server script
local repstorage = game:GetService("ReplicatedStorage")
local sellOres = repstorage.RemoteEvents:WaitForChild("SellOre")
local DataStore2 = require(1936396537)
sellOres.OnServerEvent:Connect(function(player)
local CoalStore = DataStore2("Coal", player)
local currencyStore = DataStore2("currency", player)
currencyStore:Increment(CoalStore*10)
CoalStore:Set(0)
end)
When I click on the block though, It does nothing but when I change the increment to something like 3 it adds 3 to the money and clears the coal. But I've got no idea how to do something like CoalStore *10
Please help. Thanks.
