So Im having a script where I press E to sit. (Credits to Alphexus) but I want to hide the Billboard GUI that says E when I'm sitting. Keep in mind I have a billboardGUI and an ImageLabel
-- // Services \\ -- local UserInputService = game:GetService("UserInputService") local Players = game:GetService("Players") -- // Variables \\ -- local Player = Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() -- // If character isn't loaded wait till its added local Humanoid = Character:WaitForChild("Humanoid") local Seats = workspace.Seats -- // Seats folder where all the seats local RANGE = 6 -- // How close you have to be to a seat in order to press E. -- // Functions \\ -- local function GetClosestSeat() local SeatsInRange = {} for _,seat in pairs(Seats:GetChildren()) do local mag = (seat.Position-Character.HumanoidRootPart.Position).Magnitude if mag <= RANGE then table.insert(SeatsInRange, {Seat = seat, Mag = mag}) -- // Insert into the table because the seat is in range. end end if #SeatsInRange > 0 then -- // If there are seats near the character. table.sort(SeatsInRange, function(a,b) -- // Sort the table, so the closest seat is the first index of the table. return a.Mag < b.Mag end) return SeatsInRange[1].Seat -- // Return the closest seat after sorting. else return nil -- // Return nil if no seats are close. end end UserInputService.InputBegan:Connect(function(Input, GameProcessed) if GameProcessed then return end -- // If player is typing in chat(or other gameProcessed events) then we won't run the code. if Input.KeyCode == Enum.KeyCode.E and Humanoid.Sit == false then -- // If E key is pressed and the humanoid is not currently sitting. local ClosestSeat = GetClosestSeat() if ClosestSeat ~= nil then -- // If there is a close seat. ClosestSeat:Sit(Humanoid) end end end)
You can check if a player is sitting in the seat with seat.Occupant
so you can simply add it to the line that checks if the seat is in range
if mag <= RANGE and seat.Occupant ~= nil then table.insert(SeatsInRange, {Seat = seat, Mag = mag}) -- // Insert into the table because the seat is in range. end