Anchor when jumping out of vehicle seat/unanchor when entering seat

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

An anchor script that does its thing when a player exit the vehicle seat of the model that the script in
and to unanchor when the player enters the vehicle seat

  1. What is the issue? Include screenshots / videos if possible!
    It does not work at all and it shows no errors in the output

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried to put it into a local script and add game:IsLoaded() to the script, which has not work
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local anchor = script.Parent.Parent.Anchored == true
local vehicleseat = script.Parent

if game:IsLoaded() then
local     function vehicleseat(anchor)
	if vehicleseat.Sit == true then
		anchor = false
	else if vehicleseat.sit == false then
			anchor = false
		end
	end
end
vehicleseat()

could you elaborate further on what you mean

There are a few issues with your script.

The first one is that you are setting the anchor property as an if-statement. Set it as the part you want to anchor and then set its anchored property.

Secondly, your script is only checking the value of the Sit property once. Use the .Changed event instead.

Your fixed script should look like

local partToAnchor = script.Parent.Parent
local vehicleseat = script.Parent

local function vehicleseat()
	if vehicleseat.Sit == true then
		partToAnchor.Anchored = false
	elseif vehicleseat.sit == false then
		partToAnchor.Anchored = true
	end
end

vehicleseat.Changed:Connect(vehicleseat)

Unfortunately, it doesnt help, it only makes it shake even worse than it was earlier (i’ll get a video to show you) shaking issue - YouTube shown here

Are you setting all of the parts to anchored? Based off @Friendly4Crafter 's script you could change it to get all of the children and set them to anchored.

local partToAnchor = {model}:GetChildren()
local vehicleseat = script.Parent

local function vehicleseat()
	if vehicleseat.Sit == true then
		for part in partToAnchor do
        	part.Anchored = true
	elseif vehicleseat.sit == false then
		for part in partToAnchor do
        	part.Anchored = true
	end
end

vehicleseat.Changed:Connect(vehicleseat)

If you have multiple models inside of the model, then you will need to either:

  • Use if part:IsA("Model") then and then iterate through the model again to anchor all of the children.
  • Get all of the anchorable children when you join the game and save the list to partToAnchor so you only need to iterate once.

This is however if you have multiple models included in the children. If you only have one model, then don’t worry about above.

There is no Sit property on vehicle seats. What you are looking for is Occupant. An example of usage is below.

local VehicleSeat = script.Parent

VehicleSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if VehicleSeat.Occupant then
		VehicleSeat.Anchored = false
	else
		VehicleSeat.Anchored = true
	end
end)

Sorry to bump this but just found this and I do want to say that you need to add VehicleSeat.Anchored = true otherwise it will not work

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