Scripts for Rocks
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)
Scripts in ServerScriptService==>Script
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)
Scripts in 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)