Mining
Video Tutorials
Making the Tool
Part 1
Making Resources
Part 2
Collecting Resources
Part 3
Selling Resources
Part 4
Update
Part 5
Scripts
Sell Part Script
local part = script.Parent
local canSell = true
local money = 0
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local function sell(otherPart)
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player and canSell then
canSell = false
money = money + player.leaderstats.Rocks.Value
money = money + player.leaderstats.Iron.Value * 5
money = money + player.leaderstats.Gold.Value * 25
money = money + player.leaderstats.Diamonds.Value * 100
player.leaderstats.Rocks.Value = 0
player.leaderstats.Iron.Value = 0
player.leaderstats.Gold.Value = 0
player.leaderstats.Diamonds.Value = 0
remoteEvent:FireClient(player, money)
canSell = true
end
end
part.Touched:Connect(sell)
Tool Script
local tool = script.Parent
local canMine = false
local storage = game:GetService("ServerStorage")
local function onTouch(otherPart)
if otherPart.Name == 'Rock' and canMine then
canMine = false
local minedPart = Instance.new('Part')
minedPart.Parent = game.Workspace
minedPart.Size = Vector3.new(2,1,2)
minedPart.Position = otherPart.Position + Vector3.new(math.random(-5,5), 5, math.random(-5,5))
local mineType = math.random(1,100)
if mineType < 50 then
minedPart.BrickColor = BrickColor.new('Medium stone grey')
end
if mineType > 50 and mineType < 75 then
minedPart.BrickColor = BrickColor.new('Black')
end
if mineType > 75 and mineType < 90 then
minedPart.BrickColor = BrickColor.new('Gold')
end
if mineType > 90 then
minedPart.BrickColor = BrickColor.new('Teal')
end
local scriptFile = storage["Script"]:clone()
scriptFile.Parent = minedPart
end
end
local function slash()
local str = Instance.new("StringValue")
str.Name = "toolanim"
str.Value = "Slash"
str.Parent = tool
canMine = true
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)
ServerScriptService
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local rocks = Instance.new("IntValue")
rocks.Name = "Rocks"
rocks.Value = 0
rocks.Parent = leaderstats
local iron = Instance.new("IntValue")
iron.Name = "Iron"
iron.Value = 0
iron.Parent = leaderstats
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
gold.Parent = leaderstats
local diamond = Instance.new("IntValue")
diamond.Name = "Diamonds"
diamond.Value = 0
diamond.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
ServerStorage
local part = script.Parent
local function collect(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player then
if part.BrickColor == BrickColor.new("Medium stone grey") then
player.leaderstats.Rocks.Value = player.leaderstats.Rocks.Value + 1
part:Destroy()
end
if part.BrickColor == BrickColor.new("Black") then
player.leaderstats.Iron.Value = player.leaderstats.Iron.Value + 1
part:Destroy()
end
if part.BrickColor == BrickColor.new("Gold") then
player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 1
part:Destroy()
end
if part.BrickColor == BrickColor.new("Teal") then
player.leaderstats.Diamonds.Value = player.leaderstats.Diamonds.Value + 1
part:Destroy()
end
end
end
end
part.Touched:Connect(collect)
LocalScript under TextLabel
local label = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local function displayMoney(money)
label.Text = '$ ' .. money
end
remoteEvent.OnClientEvent:Connect(displayMoney)
Mining Update
Tool Script (Handle of Tool)
local tool = script.Parent
local canMine = false
local storage = game:GetService("ServerStorage")
local swingsLeft = 10
local function onTouch(otherPart)
if otherPart.Name == 'Rock' and canMine then
canMine = false
swingsLeft = swingsLeft - 1
tool.Handle.Transparency = tool.Handle.Transparency + 0.1
local minedPart = Instance.new('Part')
minedPart.Parent = game.Workspace
minedPart.Size = Vector3.new(2,1,2)
minedPart.Position = otherPart.Position + Vector3.new(math.random(-5,5), 5, math.random(-5,5))
local mineType = math.random(1,100)
if mineType < 50 then
minedPart.BrickColor = BrickColor.new('Medium stone grey')
end
if mineType > 50 and mineType < 75 then
minedPart.BrickColor = BrickColor.new('Black')
end
if mineType > 75 and mineType < 90 then
minedPart.BrickColor = BrickColor.new('Gold')
end
if mineType > 90 then
minedPart.BrickColor = BrickColor.new('Teal')
end
local scriptFile = storage["Script"]:clone()
scriptFile.Parent = minedPart
if swingsLeft < 1 then
tool:Destroy()
end
end
end
local function slash()
local str = Instance.new("StringValue")
str.Name = "toolanim"
str.Value = "Slash"
str.Parent = tool
canMine = true
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)
Tool Script (Handle of Tool) (Rock Disappears)
local tool = script.Parent
local rock = game.Workspace.Rock
local rockBroke = false
local canMine = false
local storage = game:GetService("ServerStorage")
local swingsLeft = 15
local function onTouch(otherPart)
if otherPart.Name == 'Rock' and canMine then
canMine = false
swingsLeft = swingsLeft - 1
rock.Transparency = rock.Transparency + 0.1
local minedPart = Instance.new('Part')
minedPart.Parent = game.Workspace
minedPart.Size = Vector3.new(2,1,2)
minedPart.Position = otherPart.Position + Vector3.new(math.random(-5,5), 5, math.random(-5,5))
local mineType = math.random(1,100)
if mineType < 50 then
minedPart.BrickColor = BrickColor.new('Medium stone grey')
end
if mineType > 50 and mineType < 75 then
minedPart.BrickColor = BrickColor.new('Black')
end
if mineType > 75 and mineType < 90 then
minedPart.BrickColor = BrickColor.new('Gold')
end
if mineType > 90 then
minedPart.BrickColor = BrickColor.new('Teal')
end
local scriptFile = storage["Script"]:clone()
scriptFile.Parent = minedPart
if swingsLeft < 1 then
tool:Destroy()
end
if rock.Transparency >= 1 then
rockBroke = true
rock.CanCollide = false
wait(10)
rock.CanCollide = true
rock.Transparency = 0
rockBroke = false
end
end
end
local function slash()
local str = Instance.new("StringValue")
str.Name = "toolanim"
str.Value = "Slash"
str.Parent = tool
if not rockBroke then
canMine = true
end
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)
Sell Pad (Sell Part)
local part = script.Parent
local canSell = true
local money = 0
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local function sell(otherPart)
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player and canSell then
canSell = false
money = money + player.rocks.Value
money = money + player.iron.Value * 5
money = money + player.gold.Value * 25
money = money + player.diamond.Value * 100
player.rocks.Value = 0
player.iron.Value = 0
player.gold.Value= 0
player.diamond.Value = 0
player.PlayerGui.ScreenGui["Pop-up"].rockLabel.Text = 'Rocks: '..player.rocks.Value
player.PlayerGui.ScreenGui["Pop-up"].ironLabel.Text = 'Iron: '..player.iron.Value
player.PlayerGui.ScreenGui["Pop-up"].goldLabel.Text = 'Iron: '..player.gold.Value
player.PlayerGui.ScreenGui["Pop-up"].diamondLabel.Text = 'Iron: '..player.diamond.Value
player.leaderstats.Money.Value = money
canSell = true
end
end
part.Touched:Connect(sell)
Leaderstats and IntValues (ServerScriptService)
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Money"
money.Value = 0
money.Parent = leaderstats
local rocks = Instance.new("IntValue")
rocks.Name = 'rocks'
rocks.Value = 0
rocks.Parent = player
local iron = Instance.new("IntValue")
iron.Name = 'iron'
iron.Value = 0
iron.Parent = player
local gold = Instance.new("IntValue")
gold.Name = 'gold'
gold.Value = 0
gold.Parent = player
local diamond = Instance.new("IntValue")
diamond.Name = 'diamond'
diamond.Value = 0
diamond.Parent = player
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
New Tool Script (ServerScriptService)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local storage = game:GetService("ServerStorage")
local function giveTool(player)
local currentMoney = player.leaderstats.Money.Value
local toolPrice = ReplicatedStorage['Tool'].Price.Value
if currentMoney > toolPrice then
player.leaderstats.Money.Value = player.leaderstats.Money.Value - toolPrice
local tool = ReplicatedStorage['Tool']:Clone()
tool.Parent = player.Backpack
local tool = ReplicatedStorage['Tool']:Clone()
tool.Parent = player.StarterGear
end
end
remoteEvent.OnServerEvent:Connect(giveTool)
Script for New Resources (ServerStorage)
local part = script.Parent
local function collect(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player then
if part.BrickColor == BrickColor.new("Medium stone grey") then
player.rocks.Value = player.rocks.Value + 1
player.PlayerGui.ScreenGui["Pop-up"].rockLabel.Text = 'Rocks: '..player.rocks.Value
part:Destroy()
end
if part.BrickColor == BrickColor.new("Black") then
player.iron.Value = player.iron.Value + 1
player.PlayerGui.ScreenGui["Pop-up"].ironLabel.Text = 'Iron: '..player.iron.Value
part:Destroy()
end
if part.BrickColor == BrickColor.new("Gold") then
player.gold.Value = player.gold.Value + 1
player.PlayerGui.ScreenGui["Pop-up"].goldLabel.Text = 'Gold: '..player.gold.Value
part:Destroy()
end
if part.BrickColor == BrickColor.new("Teal") then
player.diamond.Value = player.diamond.Value + 1
player.PlayerGui.ScreenGui["Pop-up"].diamondLabel.Text = 'Diamond: '..player.diamond.Value
part:Destroy()
end
end
end
end
part.Touched:Connect(collect)
LocalScript for Pop-up (Pop-up Frame)
local openButton = script.Parent.Parent.open
local frame = script.Parent
frame.Visible = false
local function openMenu()
frame.Visible = not frame.Visible
end
openButton.MouseButton1Click:Connect(openMenu)
LocalScript for Shop (Shop Frame)
local shop = script.Parent
shop.Visible = false
local openShop = game.Workspace.ShopPart
local closeShop = script.Parent.XButton
local buy = script.Parent.BuyButton
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local canShop = true
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local function showMenu(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if humanoid and canShop then
humanoid.WalkSpeed = 0
canShop = false
shop.Visible = true
end
end
local function closeMenu()
localPlayer.Character.Humanoid.WalkSpeed = 16
shop.Visible = false
wait(2)
canShop = true
end
local function buyTool()
remoteEvent:FireServer()
end
buy.MouseButton1Click:Connect(buyTool)
closeShop.MouseButton1Click:Connect(closeMenu)
openShop.Touched:Connect(showMenu)