Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Remove BillboardGui by pressing a key and Pressing a key to jump out of seat?

Asked by 4 years ago

Hello! I am working on a chill roblox game and I need some chairs. With the help of someone from my last post, I was able to sit on seats by pressing E. But Now... I'm confused.. Q1: How do I Remove the billboard GUI That says "press E" (imageLabel) when I sit on the chair? Q2: How do I press E to get out of seat? Sit Code:

-- // 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)
0
Credits to Alphexus qMrSpooky 20 — 4y

Answer this question