I have built a game where you can drive a monorail, and I am trying to create a GUI where you can open the doors. I have gotten that to work with one monorail, however, I am having trouble when someone regens a new monorail since the game doesn’t know which monorail it should open the doors of.
Basically, why does this work: DoorParts=game.Workspace.Monorail0.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)
But not this: 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)
To clarify, the problem is the top script doesn’t work when there are two "Monorail0"s and the bottom looks like it should (since the script is inside of the monorail it should open the doors of) but it does nothing instead. Does anyone have any solution to make this work?
I don’t know much about scripting so sorry if this is an easy or obvious question. And if it helps, this script is located in a TextButton.
EDIT: Just found that the TextButtons, despite me putting in Workspace.Monorail0 goes inside of “Players” when I run it. So script.Parent.Parent etc. leads to Players.Hen8 when I’m sitting in the monorail only. I guess that means the problem is how to keep my script in Workspace.Monorail0 etc. when I run it and sit down in the VehicleSeat. Any tips for this?
From what I understand, you are having difficulties determining which Monorail is which. So the best way to do this would be to set the name of the monorail instance or a value inside, to the player who is driving’s UserID.
Another way to do it would be to create an object value inside of each player then set the value of the object value to the monorail that the player is driving.
Okay well this is most likely because the script doesn’t know which “Monorail0” the doorparts variable refers to.
The second option would solve this issue and from what you posted looks like it would work so IDK why it wouldn’t. Can you screenshot the script where this is?
What error happens when you run the second script?
I don’t get any errors relating to either script in the output, and I use a regen button model that isn’t grouped with the monorail to regen a new one.
Oh, I just looked at output while I was sitting inside of the monorail (thanks to the “play here” button) and I got this error. "DL is not a valid member of Player “Players.hen8” And it only does that with the second script which is the one that isn’t working.
Update: Just found that the TextButtons, despite me putting in Workspace.Monorail0 goes inside of “Players” when I run it. So script.Parent.Parent etc. leads to Players.Hen8 when I’m sitting in the monorail only. I guess that means the problem is how to keep my script in Workspace.Monorail0 etc. when I run it and sit down in the VehicleSeat. Any tips for this?