How to make a wall that shows and hides continuously

A bunch of people have been bombarding me with this exact question recently to my messages, so I will answer this question. I don’t get why people want to know how to do this but I’m willing to help anyway. First get your wall part ready, then add a script to it.

local wall = script.Parent -- tells the script the the wall is it's parent
local function hide() -- creating a function to hide the wall
     wall.Transparency = 1 -- Makes the wall transparent
     wall.CanCollide = false -- Makes the wall penetrable
end 

local function show() -- creating a function to show the wall
      wall.Transparency = 0 -- Makes the wall opaque
      wall.CanCollide = true -- Makes sure that nothing can go through the wall
end

while true do -- Making the action loop over and over again
     wait(1) -- add a wait function in (Studio will crash if you don't)
     hide() -- This function will hide the wall
     wait(1)
     show() -- This function will show the wall

end

This can literally be found on the developer hub. Developer Hub Why are people messaging me about this?!

3 Likes

If there are any spelling errors don’t mind them. I created this topic in a rush.
I hope this will stop people from messaging me about this question.

2 Likes

maybe new devs? idk really ¯_(ツ)_/¯

I don’t know what to say about this, it’s extremely simple. Tip: use task.wait(1) instead of wait(1), it’s a better variant.

1 Like

This is actually super inefficient. The answer below is much better.

local wall = script.Parent

while true do
    task.wait(1)
    wall.Transparency = (wall.Transparency == 1 and 0 or 1)
    wall.CanCollide = not wall.CanCollide
end
1 Like

true. But the shorter code is harder to understand compared to the longer one. Thats just how I see it

Inefficient? No. Longer? Yes. You aren’t even going to save a millisecond with that, if it saves anything.

2 Likes

Exactly, all it saves it just space.

1 Like

This should be a community tutorial, not resource.

1 Like

This script very easy, but good for beginners. Next time try to do the same but with tween service, like it’s going underground and back to normal repeatedly.

Yes, inefficient. There are two functions that control the on and off state. That’s a waste of memory. In addition, the deprecated wait should be replaced with task.wait.

Making this a tutorial just seems off. Even though it is a tutorial.

This script is… inefficient and long and begginners would probably think scripting is hard if this is their first script, here’s a suggestion.

Don’t split them into functions, they’re meaningless unless you’re gonna use them in other parts of the code

2nd, task.wait exists

3rd, peoples suggestion above

Woah. I wouldn’t even write that, make it simpler for begginners.

while true do
if Part.Transparency == 1 then
Part.Transparency = 0
else
Part.Transparency = 1
end
if Part.CanCollde == false then
Part.CanCollide = true
else
Part.CanCollide = false
end
end
--
Ik it's longer, but easier to understand

OP’s post isn’t super inefficient. It does what it needs to do with acceptable efficiency.

The one grievance I have with your code is that it’s not easily readable. I’ve been programming for a decade, and I’m not in the habit of using hacky and-or statements, so I have to take another glimpse every time I read that. I’m pretty sure they added this syntax just for simpletons like me:

local FlashyWalls = game:GetService("CollectionService"):GetTagged("FlashyWall")
while true do
    for i,v in ipairs(FlashyWalls) do
        task.wait(1)
        wall.CanCollide = not wall.CanCollide
        wall.Transparency = if wall.CanCollide then 0 else 1
    end
end

Maybe this post should be moved over to #help-and-feedback:code-review?

3 Likes

was i spamming? i got a message i was, can we not use emojis?

someone probably reported you. I’m quite sure that you are allowed to use emojis by the way

what do i do then?? idk what to do im new

I have also been misreported before. sadly, I don’t think there is anything you can do about it. This is getting unrelated to the topic by the way.