Enable a gui when a player sits. Disable a gui when player leaves

Hey, so I’m pretty stuck on this. I’ve been trying to get it to enable a gui when seated in my rocket. I plan for the gui to be enabled late on in the script. If the Player jumps out of the rocket while the gui is enabled, how can I make it disappear.

Was wondering if someone could kind of explain it aswell as well as help me code the script, otherwise I’m not really learning why and how the script works.

1 Like

very interesting
very interesting indeed

1 Like

Didnt mean it like that. I meant like help me code it.

local Seat = script.Parent

  if Seat.Occupant then
    local Player = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
    if not Player then return end
    Player.PlayerGui.GUI.Enabled = true
1 Like

the Seat | Roblox Creator Documentation property references the humanoid currently sitting. You can use the Instance | Roblox Creator Documentation method to create an event that fires every time Seat.Occupant changes. Alternatively you can track the Humanoid | Roblox Creator Documentation event and toggle the gui’s Enabled property as required.

1 Like

I was mainly just joking ur fine

1 Like

ok 1. you forgot an “end”
and 2. you don’t have an “else” after the if statement to tell it to disable

lmao was thinking that. i think i can fix it?

The reason I don’t have an else is because the Occupant would be nil. You’d need a better method to disable the Gui.

either way you still forgot an “end” :upside_down_face:

This is why I recommended the Humanoid.Seated method. Binding to it from the client lets you easily toggle the gui, you just have to check the currentSeatPart to make sure it’s the rocket’s seat.

sometimes you can’t get the humanoid in some cases

or you can but it would involve more code

this is all well and good but its conflicting with my rockets regen script. My rocket starts off by being in replicated first, then gets parented to the workspace. I dont think you can disable then enable a localscript so it says that occupant isnt a valid property.

I know this, but it’ll be more prone to exploiters. I don’t like handling things on the client.

who said you needed the client to get the humanoid

Did you even read the reply? You don’t need it, but its easier.

you said here you don’t like running things on the client and you replied to his message which involves the humanoid

1 Like

Yes, because he mentioned the Client.

oh that part slipped from my mind

I should be telling infinity what I told you then :joy: