Hey folks, so I have a system where you can blow up a bridge, and you can also repair it afterwards. The problem here is that you can only do it once, and I don’t know why. The parts of the bridge are stored in a model.
Also; The BridgeHelperPart is a part that lets you drive on roads with cars and so on, it has nothing to do with the bridge.
BridgeDetonateHandler
local detect = script.Parent.ClickDetector
local bridge = game.Workspace.Bridge
local explosionPart = bridge.PrimaryPart
local RS = game:GetService('ReplicatedStorage')
local BridgeHelperPart = game.Workspace.RoadHelperParts.BRIDGE_PART
local function detonateBridge()
local newBridge = bridge:Clone()
newBridge.Parent = RS
for i, v in pairs(bridge:GetChildren()) do
if v:IsA('BasePart') then
v.Anchored = false
end
end
BridgeHelperPart.CanCollide = false
local explosion = Instance.new('Explosion')
explosion.BlastRadius = 10
explosion.ExplosionType = Enum.ExplosionType.NoCraters
explosion.Position = explosionPart.Position
explosion.Parent = bridge
end
detect.MouseClick:Connect(function()
detonateBridge()
end)
BridgeRepairHandler
local detect = script.Parent.ClickDetector
local bridge = game.Workspace.Bridge
local RS = game:GetService('ReplicatedStorage')
local originalBridgePos = bridge.PrimaryPart.Position
local BridgeHelperPart = game.Workspace.KRAMPF.BRIDGE_PART
local function repairBridge()
bridge:Destroy()
local clonedBridge = RS:WaitForChild('Bridge')
clonedBridge.Parent = game.Workspace
clonedBridge:MoveTo(originalBridgePos)
for i, v in pairs(clonedBridge:GetChildren()) do
if v:IsA('BasePart') then
v.Anchored = true
v.CanCollide = true
end
end
print('Bridge moved')
BridgeHelperPart.CanCollide = true
end
detect.MouseClick:Connect(function()
repairBridge()
end)
Thank you for your help!