#Getting an invisible barrier to teleport with the rock

8 messages · Page 1 of 1 (latest)

old sorrel
#

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)`

#

And here's the code I have for having the block spawn in with the barriers:
`local rock = script.Parent.Rock
local invisA = script.Parent.InvisA
local invisB = script.Parent.InvisB
local invisC = script.Parent.InvisC
local invisD = script.Parent.InvisD

local rockLocations = game.Workspace.RockLocations:GetChildren()
local numLocations = #rockLocations

for place = 1, numLocations - 3 do
local rockClone = rock:Clone()
rockClone.Parent = script.Parent
rockClone.Position = rockLocations[place].Position
rockLocations[place].Free.Value = false
local invisAClone = invisA:Clone()
invisAClone.Parent = script.Parent
invisAClone.Position = rockLocations[place].Position
rockLocations[place].Free.Value = false
local invisBClone = invisB:Clone()
invisBClone.Parent = script.Parent
invisBClone.Position = rockLocations[place].Position
rockLocations[place].Free.Value = false
local invisCClone = invisC:Clone()
invisCClone.Parent = script.Parent
invisCClone.Position = rockLocations[place].Position
rockLocations[place].Free.Value = false
local invisDClone = invisD:Clone()
invisDClone.Parent = script.Parent
invisDClone.Position = rockLocations[place].Position
rockLocations[place].Free.Value = false

end

rock:Destroy()
invisA:Destroy()
invisB:Destroy()
invisC:Destroy()
invisD:Destroy()`

#

A possible solution I could tackle but would lack the knowledge for would be this:

Instead of having the invisible barriers follow the rock, have invisible barriers already spawned in all locations and have the cancollide on them turned off unless there is a rock in that position but I don't know if this would be easier or more complicated nor do I know how to check to see if a rock is in a specific position

mellow spindle
#

you could move them all together as a model

#

maybe make a single model with whatever ore, invisible barrier, and whatever else inside of it

#

and then just clone the model, and then use SetPrimaryPartCFrame to move it to wherever

#

might require some welding but ultimately would make the process less complicated

#

also, this is codeblocking