Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Check if Player is in a Vehicle Seat?

I have a lot of vehicles in my game, and some are very large. I've made a script that limits how far the camera goes, but I want the max camera range to increase when a player is in a vehicle, specifically, when they're sitting in a vehicle seat.

Here's the camera script I have so far (in a localscript):

local player = game.Players.LocalPlayer

player.CameraMaxZoomDistance = 20
player.CameraMinZoomDistance = 0

How can I detect when the LocalPlayer is inside a vehicle seat?

For instance:

local player = game.Players.LocalPlayer

player.CameraMaxZoomDistance = 20
player.CameraMinZoomDistance = 0

while true do
	wait()
	if insideseat then
		player.CameraMaxZoomDistance = 40
	else
		player.CameraMaxZoomDistance = 20
	end
end

--or something like that that detects it

Everything I've found so far works when the player is in ANY seat, not just a vehicle seat, which is not what I want. How can I solve this?

Thanks for your help :)

Edit: I would also like to have a way to get the parent of the seat the player is in to detect the vehicle since they're different sizes and I want the camera to adjust differently for each.

1 answer

✓ Accepted answer

There's an event of Humanoid called Humanoid.Seated. You can use this to check if the humanoid is sitting, and also sitting in a current part. There's 2 parameters, active (bool) and the currentSeatPart (instance). So here's an example:

local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")

humanoid.Seated:Connect(function(active,currentSeat)
	if active then
		if currentSeat.Name == "Seat" then
			print("I'm sitting on "..currentSeat.Name)
		end
	end
end)

(Note: Don't use a while loop, if you can use an event, it will be really helpful and it can help you optimise your code.)

1 comment

1

Thanks! I guess that should solve both of my problems.

This discussion is preserved as it was. New answers, comments, and votes are closed.