How can i make this with stairs?

I have staircases for an obby that dissapear and reappear on touch, all the parts in the stairs have a script that make them do that, i want to make it so its one script that makes them do the disapeearing and reappearing on touch instead of alot of scripts being in each script, how can i do this? this is the script

local block = script.Parent
db = false

function onTouch()
	if db == false then
		db = true
		for i = 1, 20 do
			block.Transparency = i/20
			wait(0.05)
		end
		block.CanCollide = false
		wait(2)
		block.CanCollide = true
		block.Transparency = 0
		db = false
	end
end

block.Touched:connect(onTouch)

You can use collection service or you can group in a model and use :GetChildren on the parts and loop through them.

You probably can just use Ai to do it for you.

local folder = script.Parent
for i, block in pairs(folder:GetChildren()) do
  if not block:IsA("Part") then return end
  local db = false
  block.Touched:Connect(function()
    if db == false then
		db = true
		for i = 1, 20 do
			block.Transparency = i/20
			wait(0.05)
		end
		block.CanCollide = false
		wait(2)
		block.CanCollide = true
		block.Transparency = 0
		db = false
  end)
end

Let me know if this works

1 Like

i tried it on my stairs and it works fine, thanks for the script :+1:

1 Like

This also works as well when i tried doing it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.