How can I make an Q to sit thing, with a billboardgui that says “Q to sit” on the chair, using user input service and collectionservice?
I have already followed @Crazyman32 's video, but when I replace the screenGui (what he used) for a BillboardGui that will appear on my seat, the gui flashes.
Here is my code:
local SEATS_TAG = “Seats”
local SIT_DISTANCE = 5local cs = game:GetService(“CollectionService”)
local uis = game:GetService(“UserInputService”)local player = game.Players.LocalPlayer
local humanoid = script.Parent:WaitForChild(“Humanoid”)local seats = cs:GetTagged(SEATS_TAG)
local qGui = script:WaitForChild(“qGui”)local closestSeat = nil
uis.InputBegan:Connect(function(input, processed)
if not processed and input == Enum.KeyCode.Q then
if (closestSeat) then
if (humanoid.Sit) then
humanoid.Jump = true
else
closestSeat:Sit(humanoid)
end
end
end
end)cs:GetInstanceAddedSignal(SEATS_TAG):Connect(function(seat)
table.insert(seats, seat)
end)cs:GetInstanceRemovedSignal(SEATS_TAG):Connect(function(seat)
seats = cs:GetTagged(SEATS_TAG)
end)while (true) do
local seat = nil
local minDist = math.huge
for _,s in pairs(seats) do
local distance = player:DistanceFromCharacter(s.Position)
if (distance < SIT_DISTANCE and distance < minDist) then
seat = s
minDist = distance
end
end
closestSeat = seat
if closestSeat ~= nil then
if not closestSeat:FindFirstChild(“qGui”) then
local makeQgui = qGui:Clone()
makeQgui.Parent = closestSeat
makeQgui.Enabled = true
else
closestSeat:WaitForChild(“qGui”):Destroy()
end
end
wait(0.2)
end
Heres what happens: https://gyazo.com/6e887d4cd0581fe033a9f4cf0a60ba56