How can i return back in a function?

i cannot describe my issue in the topic, but i will do my best to write

  1. What do you want to achieve? I made a bridge to fall down whenever a player walk on it.

  2. What is the issue? It worked probably, but i want it to return the bridge back after a few seconds.

  3. What solutions have you tried so far? I tried to use return but it just make me more confused.

this is the falling code.

local main1 = script.Parent.Part1
local main2 = script.Parent.Part2
local main3 = script.Parent.Part3
local main4 = script.Parent.Part4

--local distance = 3

--local debounce = false
--local cd = 1

local function breakNow()
		
	main1.Anchored = false
	main2.Anchored = false
	main3.Anchored = false
	main4.Anchored = false
		
end

script.Parent.Main.Touched:Connect(breakNow)

Please help! Any help from you would receive a big appreciate from me <3

Save the position of every part before they fall.

local self = script.Parent
local parts = {}

local cooldown = 5
local debounce = false

for _, v in next, self:GetChildren() do
    if v:IsA("BasePart") then
        parts[v] = v.CFrame
    end
end

local function breakNow()
    if debounce then return end
    debounce = true
    
    for part in next, parts do
        part.Anchored = false
    end
    task.wait(cooldown)

    for part, pos in next, parts do
        part.Anchored = true
        part.CFrame = pos
    end
    
    debounce = false
end

self.Main.Touched:Connect(breakNow)

If you don’t want Main to fall, then put this right before the .Touched

parts.Main = nil
1 Like

you could clone the part and unanchor the clones, but turn off cancollide and transparency set to 1 for the real bridge.

Cloning is not recommended because creating new instances is expensive. Imagine cloning a bridge with 5,000 parts. CFraming parts back to their original is actually very cheap and there are PartCache systems out there demonstrating this.

some part didn’t recover. It seems like i now why, below those parts is water, some part didn’t fall out of the world because stuck in the water…