Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can someone help with a disappearing door?

Asked by
Scerzy 85
9 years ago

Well I know it would be easy to make a door disappear and reappear by using an onTouch function and setting it's can-collide to be false and its transparency to fade to 1. But I need help. Is there any way that I can have a tool in my starterpack where if I click, the door dissappears, but if I click again, the door reappears? I already know how to do the script for the dissappearing part and the reappearing part, I just need someone to point me in the right direction.

Also, if this is not possible, I can settle for a button where if I click, it fades and if I click again, it reappears. I just don't know the function for it.

This is my fading script using an onTouch function. Hope that helps somehow.

Brick = script.Parent

fading = false

Brick.Touched:connect(function(part)

    if not fading then

        fading = true

        for i = 1, 10 do

            Brick.Transparency = Brick.Transparency + .1

            wait(.1)

        end

        wait(2)

        Brick.Transparency = 0

        fading = false

    end

end)

local Brick = script.Parent



Brick.Changed:connect(function(prop)

    if prop == "Transparency" then

        if Brick.Transparency >= 1 then

            Brick.CanCollide = false

        else

            Brick.CanCollide = true

        end

    end

end)

1 answer

Log in to vote
0
Answered by
yumtaste 476 Moderation Voter
9 years ago

You can listen for the Equipped event of a tool, get the mouse, then listen for a click, check if the door was clicked on, then take appropriate action. Here, I'll give you an example:

local door = workspace:FindFirstChild("Door") --change this to the location of the door

script.Parent.Equipped:connect(function(mouse)
if mouse.Target then
if mouse.Target == door then
--take appropriate action here
end
end
end)
0
Thank you, this seems like it'd work like a charm. However, one quick question. Where would this script be places? In other words, what would its parent be? Scerzy 85 — 9y
0
It would be a child of a Tool. If I answered your question, please mark it as accepted and upvote! yumtaste 476 — 9y
Ad

Answer this question