Hi!
I am currently working on a vehicle script and am looking for a way to search for the vehicleseat I am sitting on.
For example,
local a = game.Workspace.vehicle
The above script may cause an error when there are multiple “vehicle” models.
(My vehicle will have multiple models of the same model using a spawner.)
I’m trying to control a vehicle from a GUI script cloned into the player, so please advise on how to find the model containing the Vehicleseat the player is sitting on!
You could use magnitude to see how close the player is to the seat or you can loop through all of the seats and check if the occupant == to your character i hope that kinda helps
function getSeat()
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local Seat = humanoid.SeatPart.Parent
end
getSeat()
It works with a local script cloned into the player.
local Game = game
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid")
local function OnSeatPartChanged()
print(Humanoid.SeatPart.Name)
end
Humanoid:GetPropertyChangedSignal("SeatPart"):Connect(OnSeatPartChanged)