Hello, I need help, So this is scripted the functions is to :GetChildren() in a Folder to detect car, then a function detects the nearest seat, but the problem here, is that it’s only detecting like one Seat not all, it’s only placing the adornee to ONE Seat, not all!
GIF Showing error: https://gyazo.com/4318e760ef2b1282441713f8a7ad6a3c
Image of the Model: https://gyazo.com/90c51fd721e7db95fdb3a82ab7a87e2b
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local character = Players.LocalPlayer.Character
local ClosestVehicle, ClosestSeat, Gui, CurrentSeat
character.Humanoid.Died:Connect(function()
if Gui then
Gui:Destroy()
end
script.Disabled = true
end)
RunService.Heartbeat:Connect(function()
for i,v in pairs(game.Workspace.Vehicles:GetChildren()) do
local mag = (v.DriveSeat.Position - character.HumanoidRootPart.Position).Magnitude
if mag <= 20 then
ClosestVehicle = v
if v then
CheckForNearestSit(ClosestVehicle)
print(ClosestSeat)
end
end
end
end)
UserInputService.InputBegan:Connect(function(Key, GameProcessed)
if Key.KeyCode == Enum.KeyCode.E then
if (ClosestSeat.Position - character.HumanoidRootPart.Position).Magnitude <= 6 then
if CurrentSeat == nil then
CurrentSeat = Gui.Adornee
CurrentSeat:Sit(character.Humanoid)
else
CurrentSeat:Sit(nil)
CurrentSeat = nil
end
end
end
end)
function CheckForNearestSit(Vehicle)
for i,v in pairs(Vehicle:GetChildren()) do
if v:IsA("Seat") or v:IsA("VehicleSeat") then
local mag = (v.Position - character.HumanoidRootPart.Position).Magnitude
if mag <= 6 then
ClosestSeat = v
Gui = script.Enter
Gui.Adornee = v or ClosestSeat
else
Gui = script.Enter
Gui.Adornee = nil
Gui = nil
end
end
end
end