How do I make a button drawbridge?

I have been trying to make a button that connects to a drawbridge, i am hoping that when you click the button, it will make the drawbridge go up, and the button goes green. and when the button is clicked again, the drawbridge goes back down.

Here is an example on how the drawbridge will function.Drawbridge - YouTube

This is not a topic on the dev hub yet, and their is no tutorials on YouTube. I am very new to scripting so i do not know exactly how to script yet. Thank you for everyone who replies :smiley:

1 Like

Have you tried using

Button.MouseButton1Click:Connect(function())

end)

I have not yet, but i am not exactly sure how to use a function, can you help me with what to do inside that function?

1 Like

You can try to make it as the youtube tutorial says.
But changing the script. For example, if you are using a ClickDetector inside a Part, then you can put the script inside the part and do:

 local hinge = script.Parent.HingeConstraint

script.Parent.ClickDetector.MouseClick:Connect(function())
       hinge.TargetAngle = 30
       wait(2)
        hinge.TargetAngle = 0
end)

This may work, Hope it helps!

1 Like

ok, i will go try it out, and does this script make it go back down when clicked again?

1 Like

You can try making a bool outside of the function called isUp and set it to false. Inside the function put isUp = not isUp and again inside the function do

if not isUp then
--make it go up
else
--make it go down
end

Sorry for the terrible grammar I am on mobile right now and I write kinda fast.

i do not know how to do that @Intencidy. sorry, i am very new and is watching alvinblox tutorials on learning to script.

Its all good! Just put local isUp = false outside of the function and put the stuff in the other reply in the function.

No, this will make it so after 2 seconds, it goes down automatically. But if you want to make it so it works when clicked again then you can do:

  • Add another script inside the Part and names it like you want. And go to it’s properties and disable it.
    Then inside it write:
local hinge = script.Parent.HingeConstraint
local scriptOfTheOtherPost = script.Parent.ScriptOfTheOtherPostName

script.Parent.ClickDetector.MouseClick:Connect(function())
        hinge.TargetAngle = 0
        scriptOfTheOtherPost.Disabled = false
        script.Parent.Disabled = true
end)

then on the script I wrote on the other post, rewrite it doing this:

local hinge = script.Parent.HingeConstraint
local MakeTheBridgeGoDown = script.Parent.NameOfTheScriptAbove

script.Parent.ClickDetector.MouseClick:Connect(function())
       hinge.TargetAngle = 30
       MakeTheBridgeGoDown.Disabled = false
       script.Parent.Disabled = true
  end)

This should work, if it doesn’t let me know and I will check! :smiley: Hope it helps!

1 Like

This does seem like a script that works, but i am not able to figure out how to exactly do this, the bridge does not move when i click it. and it just spins when i touch it. your very good at explaining its just me who can not figure this out, sorry.

1 Like

it is also saying this " NameOfTheScriptAbove is not a valid member of Part “Workspace.Bridge” - Server - Script:2"

1 Like

Ah, you need to put “NameOfTheScriptAbove” To the name that you put to your script. for example, if you named it “Friend” then you should change NameOfTheScriptAbove to Friend.

Thank you for all your help, i got it!

1 Like

Np!. Glad I could help you! :slight_smile: