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

My textbox GUI door opener script isn't working? (MY CODE IN ANSWERS)

Asked by 6 years ago
Edited 6 years ago

What did I do wrong? I'm trying to make a textbox that on click it opens that make a part be able to go through and if you click it again it the part isn't able to go through? (CODE IN ANSWERS)

0
The code you provided in the answers wouldn't work with an actual game as you seem to be setting properties of a door in a local script, instead try making it so that when a player clicks the button, it fires a remote event that opens and closes the door theking48989987 2147 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago

Hey, I fixed up the script for you. Also, most importantly use a "Text Button" instead of a Text Box.

01local button = script.Parent
02local door = game.Workspace.Door
03 
04door.Anchored = true
05 
06button.MouseButton1Click:Connect(function()
07    if door.CanCollide == true then
08        door.CanCollide = false
09    elseif door.CanCollide == false then
10        door.CanCollide = true
11    end
12end)
Ad
Log in to vote
0
Answered by 6 years ago
01local Button = script.Parent
02Door = game.workspace.Door
03 
04function onClick()
05    if Door.CanCollide == false then
06        Door.CanCollide == true
07    else Door.CanCollide == true then
08        Door.CanCollide == false
09 
10    end
11end
12 
13Button.MouseButton1Click:connect(OnClick)
Log in to vote
0
Answered by
Syclya 224 Moderation Voter
6 years ago
01local Button = script.Parent
02local Door = game:GetService("Workspace"):WaitForChild("Door")
03Door.Anchored = true
04 
05Button.MouseButton1Click:Connect(function()
06if Door.CanCollide then
07Door.CanCollide = not Door.CanCollide
08elseif not Door.CanCollide then
09Door.CanCollide = true
10end
11end)

Answer this question