Destroy BillboardGui when sitting, place it back when leaving seat?
The title says it all. How do I Destroy a BillboardGui Inside a part when sitting?
Workspace V
Seats (folder) V
Seat V
GUI (BillboardGUI)
Is there a way to find all the GUIs from the seats folder and destroy them when sitting?
Also, place them back after leaving a seat
Notes:
* I want to have only the player SITTING having his BillboardGUI removed
LocalScript in StarterGui:
02 | local UserInputService = game:GetService( "UserInputService" ) |
03 | local Players = game:GetService( "Players" ) |
06 | local Player = Players.LocalPlayer |
07 | local Character = Player.Character or Player.CharacterAdded:Wait() |
08 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
10 | local Seats = workspace.Seats |
14 | local function GetClosestSeat() |
15 | local SeatsInRange = { } |
16 | for _,seat in pairs (Seats:GetChildren()) do |
17 | local mag = (seat.Position-Character.HumanoidRootPart.Position).Magnitude |
18 | if mag < = RANGE and seat.Occupant = = nil then |
19 | table.insert(SeatsInRange, { Seat = seat, Mag = mag } ) |
24 | if #SeatsInRange > 0 then |
25 | table.sort(SeatsInRange, function (a,b) |
28 | return SeatsInRange [ 1 ] .Seat |
34 | UserInputService.InputBegan:Connect( function (Input, GameProcessed) |
35 | if GameProcessed then return end |
37 | if Input.KeyCode = = Enum.KeyCode.E and Humanoid.Sit = = false then |
38 | local ClosestSeat = GetClosestSeat() |
39 | if ClosestSeat ~ = nil then |
40 | ClosestSeat:Sit(Humanoid) |