Trying to fix my periscope

Hello,
So I made a periscope. Unfortunately it is not yet working perfectly. It uses a VehicleSeat to control the rotation / swivel of the periscope, and the camera is changed via a RemoteEvent and local script. The player can’t walk onto the VehicleSeat, as it’s disabled, and instead triggered by a ProximityPrompt.

The main issue is that about 50% of the time, I activate the ProximityPrompt, and the player is teleported to the VehicleSeat (but not seated on it), and free to walk away. When the player returns within range of the prompt, they are automatically seated in the seat, and using the periscope. Not only am I asking if anyone can point out why this is happening, but also is there a more efficient way to do this? Sorry about the long post, and thanks in advance for any help whatsoever! Here is the script:

ProximityPrompt Server Script (Sibling of the ProximityPrompt)

local VehicleSeat = script.Parent.Parent:FindFirstChild("VehicleSeat") -- Adjust the path to the VehicleSeat
if not VehicleSeat then
	warn("VehicleSeat not found")
	return
end

local ProximityPrompt = script.Parent:FindFirstChildOfClass("ProximityPrompt")
if not ProximityPrompt then
	warn("ProximityPrompt not found")
	return
end

local seatOccupantConnection = nil

local function onSeatOccupantChanged()
	if not VehicleSeat.Occupant then
		VehicleSeat.Disabled = true
		if seatOccupantConnection then
			seatOccupantConnection:Disconnect()
			seatOccupantConnection = nil
		end
	end
end

ProximityPrompt.Triggered:Connect(function(player)
	if not VehicleSeat.Occupant then
		VehicleSeat.Disabled = false -- Enable the seat
		

		-- Teleport the player's character to the VehicleSeat
		local character = player.Character
		if character and character:FindFirstChild("HumanoidRootPart") then
			character:SetPrimaryPartCFrame(VehicleSeat.CFrame)
		end

		-- Disconnect any existing connection and set up a new one
		if seatOccupantConnection then
			seatOccupantConnection:Disconnect()
		end
		seatOccupantConnection = VehicleSeat:GetPropertyChangedSignal("Occupant"):Connect(onSeatOccupantChanged)
	end
end)

Here is a video of the main issue, and an image of the hierarchy in the Explorer.

robloxapp-20240116-1730086.wmv (2.1 MB)

periscope hierarchy

I don’t see where you are actually putting the player in the seat with the :Sit() function?
Are you just teleporting and hoping they move to trigger the sitting?

1 Like

I tried using the :Sit() function, but this just made the player sit on the ground. Perhaps I messed it up?

Not sure if it would disable the controls, I think it doesnt, but maybe keep the seat in a ‘disabled’ state, and try using the :sit()

1 Like

That didn’t work either unfortunately. I’m not sure if a player can sit in a disabled seat, and if they are sitting in it when it becomes disabled, they would get kicked off automatically no? That’s what I thought the issue was when I tried it anyways.

I will open up studio and try some thing with the seat, to be sure.

1 Like

Thank you, much appreciated. I will keep trying to implement to :Sit() funciton.

So I’m getting this error when I try the :Sit() function:

Unable to assign property SeatPart. Property is read only - Server - PeriPrompt:40

I was looking through the code of one of those cars you can find in the toolbox, that lets you press ‘E’ to use it.

I that car, the seat is Disabled, always.
and they use the :Sit() method…

image

As for your error, show me the line of code that is giving the error

1 Like

Ahh right, weird. I’ll keep trying anyway. Here is the line of code giving the error:

	humanoid.SeatPart = VehicleSeat

You can’t manually assign the SeatPart property, you can only read from it.
It gets assigned when you use the :Sit() command, or I think it might get assigned also if you simply put
a SeatWeld, but not sure on that.

1 Like

If you’d like I have a seat script I got from the toolbox years ago that allows you to position the player on the vehicleseat (welded as per usual) and edit their arms/legs/head/sitting position parameters so you could have them in a standing pose instead while using it.
It’s for R6 but it could be modified for R15 too.
The player would have to jump to get off the seat still, but the seat still registers throttle and steering inputs.
I can get it for you later tonight if you’d like.

1 Like

Thank you very much! It seems to be working perfectly now. I just did

VehicleSeat:Sit(character.Humanoid)

Thanks again! Wish I thought of looking in the toolbox for examples lol.

1 Like

No need, much appreciated though. The animation I have handles the player’s pose when they’re using the periscope. I have yet to work out the player leaving the seat without jumping, but I’m sure that won’t be too difficult. Thank you very, very much for your help!

When looking through that car script, I noticed this…

image

Maybe it is where they are disabling jump?

1 Like

True, that will be helpful! Thanks once again!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.