How to eject a character from a seat?

the title pretty much explains my problem. i have tried to make the character jump and SetPrimaryPartCFrame on the character but none worked.

1 Like

There is a property named Humanoid.Sit which returns a bool value. Read more here: Humanoid | Documentation - Roblox Creator Hub

local function PromptTriggered(object, player)
    local char = player.Character
    local hum = char.Humanoid
    
    hum.Sit = false 
end

What are you trying to achieve here? That’s my only guess.

no, the prompt is used to sit, but if the player is not the owner its supposed to eject him. heres my script:

script.Parent.Changed:Connect(function()
	if script.Parent.Occupant == nil then
		script.Parent.SitPrompt.Enabled = true
	elseif script.Parent.Occupant.Parent.Name ~= script.Parent.Parent.Parent.ToSave.Owner.Value then
		script.Parent.Occupant.Sit = false
		script.Parent.SitPrompt.Enabled = true
	end
end)

You need to reference the occupant’s humanoid to change their sit property.

1 Like

1 Like

Are you receiving an error? It’s hard to debug your script without knowing what’s going on

nope, im not getting any errors

Then I’d suggest double checking the value of this as it’s probably not registering as not equal to.

script.Parent.Changed:Connect(function()
	if script.Parent.Occupant == nil then
		script.Parent.SitPrompt.Enabled = true
	elseif script.Parent.Occupant.Parent.Name ~= script.Parent.Parent.Parent.ToSave.Owner.Value then
		print("ejecting the character")
		script.Parent.Occupant.Sit = false
		script.Parent.SitPrompt.Enabled = true
	end
end)

image

Another method of getting the player out of the seat would be to manually destroy the seat weld (which is parented to the seat as the player touches the seat).

seat:FindFirstChild("SeatWeld"):Destroy()

image

Tested it in a game and it works perfectly fine, so I’d assume it’s something to do with your SitPrompt script.

just did this and it works

script.Parent.Changed:Connect(function()
	if script.Parent.Occupant == nil then
		script.Parent.SitPrompt.Enabled = true
	elseif script.Parent.Occupant.Parent.Name ~= script.Parent.Parent.Parent.ToSave.Owner.Value then
		if script.Parent:FindFirstChild("SeatWeld") ~= nil then
			repeat
				if script.Parent.SeatWeld.Parent ~= nil then
					script.Parent.SeatWeld:Destroy()
				end
				wait()
			until script.Parent:FindFirstChild("SeatWeld") == nil
		end
		script.Parent.SitPrompt.Enabled = true
	end
end)
2 Likes

Searching through the devforum, I believe a simple wait(0.1) before destroying the seat weld may also suffice (as this seems to be a common issue due to the the seat weld being destroyed right as it is created).

yeah simple wait worked as well, but if someone was laggy it could maybe take a bit longer so i just added a repeat loop