Here's the code I currently have for the rock breaking and finding a new location to teleport to:
`local label = script.Parent.Health
local rock = script.Parent
--local invisA = script.Parent
--local invisB = script.Parent
--local invisC = script.Parent
--local invisD = script.Parent
local rockLocations = game.Workspace.RockLocations:GetChildren()
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
swingsLeft -= 1
label.Green.Size = UDim2.new(swingsLeft/10, 0, 1, 0)
end
if swingsLeft <= 0 then
local currentPos = rock.Position
local currentPlace = nil
for _, place in pairs (rockLocations) do
if currentPos == place.Position then
currentPlace = place
break
end
end
for _, place in pairs(rockLocations) do
if place.Free.Value == true then
rock.Position = place.Position
place.Free.Value = false
break
end
end
if currentPlace then
currentPlace.Free.Value = true
end
swingsLeft = 10
label.Green.Size = UDim2.new(1,0,1,0)
local crystals = ReplicatedStorage:FindFirstChild('Crystals'):GetChildren()
local randomCrystal = crystals[math.random(1,#crystals)]:Clone()
randomCrystal.Parent = game.Workspace
randomCrystal.Position = currentPos
local CollectScript = ServerStorage:FindFirstChild('Collect'):Clone()
CollectScript.Parent = randomCrystal
end
end
rock.Touched:Connect(onTouch)`