Mining Update

PART 1

Script for Tool

local tool = script.Parent

local function mine()

local str = Instance.new("StringValue")

str.Name = "toolanim"

str.Value = "Slash"

str.Parent = tool

tool.Mining.Value = true

wait(0.25)

tool.Mining.Value = false

end



tool.Activated:Connect(mine)

Script for Rock

local label = script.Parent.Health

local rock = script.Parent

local hit_sound = rock.Hit


local swingsLeft = 10


local function onTouch(otherPart)

local tool = otherPart.Parent

if tool:IsA('Tool') and tool.Mining.Value == true then

hit_sound:Play()

swingsLeft -= 1

label.Green.Size = UDim2.new(swingsLeft/10, 0, 1, 0)

end

if swingsLeft <= 0 then

rock:Destroy()

end

end


rock.Touched:Connect(onTouch)

PART 2

Rock Script

local label = script.Parent.Health

local rock = script.Parent

local hit_sound = rock.Hit

local rockPos = rock.Position


local ReplicatedStorage = game:GetService('ReplicatedStorage')


local swingsLeft = 10


local function onTouch(otherPart)

local tool = otherPart.Parent

if tool:IsA('Tool') and tool.Mining.Value == true then

hit_sound:Play()

swingsLeft -= 1

label.Green.Size = UDim2.new(swingsLeft/10, 0, 1, 0)

end

if swingsLeft <= 0 then

rock:Destroy()

local crystals = ReplicatedStorage:FindFirstChild('Crystals'):GetChildren()

local randomCrystal = crystals[math.random(1, #crystals)]:Clone()

randomCrystal.Parent = game.Workspace

randomCrystal.Position = rockPos

end

end


rock.Touched:Connect(onTouch)

PART 3

Rock Script

local label = script.Parent.Health

local rock = script.Parent

local hit_sound = rock.Hit

local rockPos = rock.Position


local ReplicatedStorage = game:GetService('ReplicatedStorage')

local ServerStorage = game:GetService('ServerStorage')


local swingsLeft = 10


local function onTouch(otherPart)

local tool = otherPart.Parent

if tool:IsA('Tool') and tool.Mining.Value == true then

hit_sound:Play()

swingsLeft -= 1

label.Green.Size = UDim2.new(swingsLeft/10, 0, 1, 0)

end

if swingsLeft <= 0 then

rock:Destroy()

local crystals = ReplicatedStorage:FindFirstChild('Crystals'):GetChildren()

local randomCrystal = crystals[math.random(1,#crystals)]:Clone()

randomCrystal.Parent = game.Workspace

randomCrystal.Position = rockPos

local collectScript = ServerStorage:FindFirstChild('Collect'):Clone()

collectScript.Parent = randomCrystal

end

end


rock.Touched:Connect(onTouch)

ServerScriptService

local function onPlayerJoin(player)

local inventory = Instance.new('Folder')

inventory.Name = 'Inventory'

inventory.Parent = player

local pink = Instance.new('IntValue')

pink.Name = 'Pink'

pink.Parent = inventory

local blue = Instance.new('IntValue')

blue.Name = 'Blue'

blue.Parent = inventory

local yellow = Instance.new('IntValue')

yellow.Name = 'Yellow'

yellow.Parent = inventory

local green = Instance.new('IntValue')

green.Name = 'Green'

green.Parent = inventory

local red = Instance.new('IntValue')

red.Name = 'Red'

red.Parent = inventory

local black = Instance.new('IntValue')

black.Name = 'Black'

black.Parent = inventory

end


game.Players.PlayerAdded:Connect(onPlayerJoin)

ServerStorage (Collect)

local crystal = script.Parent


local function collect(otherPart)

local player = game.Players:FindFirstChild(otherPart.Parent.Name)

if player then

local crytalType = crystal.Name

local crystalStat = player.Inventory:FindFirstChild(crytalType)

if crystalStat then

crystal:Destroy()

crystalStat.Value = crystalStat.Value + 1

end

end

end


crystal.Touched:Connect(collect)


Part 4

Inventory Local Script

local frame = script.Parent


local player = game.Players.LocalPlayer


local playerInventory = player:WaitForChild('Inventory')


local openButton = frame.Open

local isOpen = true


local crystal1 = playerInventory:FindFirstChild('Pink')

local crystal1Label = frame.Amount1


local crystal2 = playerInventory:FindFirstChild('Green')

local crystal2Label = frame.Amount2


local crystal3 = playerInventory:FindFirstChild('Red')

local crystal3Label = frame.Amount3


local crystal4 = playerInventory:FindFirstChild('Yellow')

local crystal4Label = frame.Amount4


local crystal5 = playerInventory:FindFirstChild('Blue')

local crystal5Label = frame.Amount5


local crystal6 = playerInventory:FindFirstChild('Black')

local crystal6Label = frame.Amount6


crystal1.Changed:Connect(function()

crystal1Label.Text = crystal1.Value

end)


crystal2.Changed:Connect(function()

crystal2Label.Text = crystal2.Value

end)


crystal3.Changed:Connect(function()

crystal3Label.Text = crystal3.Value

end)


crystal4.Changed:Connect(function()

crystal4Label.Text = crystal4.Value

end)


crystal5.Changed:Connect(function()

crystal5Label.Text = crystal5.Value

end)


crystal6.Changed:Connect(function()

crystal6Label.Text = crystal6.Value

end)



openButton.MouseButton1Click:Connect(function()

if isOpen then

frame:TweenPosition(UDim2.new(-0.2, 0, 0.049, 0), 'Out', "Quad", 2, true)

else

frame:TweenPosition(UDim2.new(0, 0, 0.049, 0), 'Out', "Quad", 0.5, true)

end

isOpen = not isOpen

end)