GUI Door Script

Hi, I am building a game where you can drive a monorail, and I want you to be able to sit down and get a GUI where you can open the doors. I currently have it where when you sit down, you get two TextButtons (Open doors and Close doors) and I had this script for it. (DL stands for Doors/Left)

DoorParts=script.Parent.Parent.Parent.Parent.DL

function onButtonClicked()
	DoorParts.Door.Transparency=1
	DoorParts.Door.CanCollide=false
	DoorParts.Door2.Transparency=1
	DoorParts.Door2.CanCollide=false
	DoorParts.Hello.Transparency=1
	DoorParts.Hello.CanCollide=false
	DoorParts.Bye.Transparency=1
	DoorParts.Bye.CanCollide=false
	
end
script.Parent.MouseButton1Down:connect(onButtonClicked)

The problem is when a player sits down, the actual GUI is stored in players, not workspace, so when I press the button it goes to Players.Hen8 instead of DL.

Using game.Workspace.Monorail0 (The monorail’s name).Doors (DL) in place of the first line doesn’t work because you can regen the monorail, meaning you can have two identical monorail0s. So without using that,

How can I alter this code to open the doors of the exact monorail a player is sitting in and no others?

Thank you!

Sorry if this explanation is unclear, it’s pretty specific so it’s hard to explain.

You can find the current monorail you are sitting in using the character’s Humanoid.SeatPart. This will give you the seat, and from there you can find the rest of the monorail.

1 Like

How do I get to the Humanoid.SeatPart from game.Players.(me)? I can only find humanoid.SeatPart in game.Workspace.(me) and I don’t know how to get there from .Players.

You can get to a player’s character using Player.Character, and from there the humanoid is a child of the character. Be warned that the character can sometimes be replaced or missing.

1 Like

It worked! It now only opens the doors of the monorail I want. Thank you so much!

1 Like