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

Trying to make gui button open and close a door? [SOLVED]

Asked by 7 years ago
Edited 7 years ago

I'm a beginner so it is most likely very obvious.

if game.Workspace.Cheese.CanCollide == true then
end

script.Parent.MouseButton1Click:connect(function()
    game.Workspace.Cheese.CanCollide = false
end)


function numbertwo()
    game.Workspace.Cheese.CanCollide = true
    end

if game.Workspace.Cheese.CanCollide == false then
end

script.Parent.MouseButton1Click:connect(function(numbertwo)
    game.Workspace.Cheese.CanCollide = true

end)

The Opening Works, it's closing it that's the problem. Cheese = My door btw Can someone please tell me what I did wrong so I don't make this mistake in the future.

2 answers

Log in to vote
0
Answered by
VoltCode 101
7 years ago
collide = true

script.Parent.MouseButton1Click:connect(function()
    if collide == true then
        game.Workspace.Cheese.CanCollide = false
        collide = false
    else
        game.Workspace.Cheese.CanCollide = true
        collide = true
    end
end)

If this doesn't work, tell me in the chat and I'll fix it.

Ad
Log in to vote
0
Answered by
DeepDev 101
7 years ago
Edited 7 years ago

Your problem is that you misplaces your function at the the end. It could be easier.

function openclose ()
local door= game.Workspace.Cheese
if script.Parent.Text== "Open door" then --"Open door" is just a exampe, change it to whatever your button says.
door.CanCollide= false
script.Parent.Text="Close Door" -- Again "Close door" is just an example, change it however you want it.
else if script.Parent.Text== "Close door" then 
door.CanCollide= true
script.Parent.Text="Open door" -- change open door to the text you have in the beginning
end
end
end
script.Parent.MouseButton1Click:connect(openclose)

I wrote this all on mobile and havent tested this myself, there is a high possibility that i mistyped something. But in principle it has to work.

Answer this question