F to sit (proximity prompt)

Topic - F to sit
Hello, another post to help the development of my plane.

How can I make someone sit in a seat when a proximity prompt is triggered
and how can I make a GUI and control script enable for only the occupant of the seat?
Thanks,
–Luke

7 Likes

So,

For proximity prompt, you’re able to teleport the player relative to the seat, and turn their walkspeed 0 for 1 second so that they spawn on top of the seat, and they are sat and can’t move. To detect WHO is sitting on the seat, there is actually a humanoid.Sit feature that you can use in your global script. You’re then able to find the player, the playerGui and enable that GUI for only the player. It can be put in a global script. I hope this helps.

3 Likes

How would I use the “Humanoid.Sit” Feature?

2 Likes
2 Likes

Okay thanks, but also how do I get the players character and what part of the character do I teleport.

2 Likes

You’re able to do this:

game.Players.PlayerAdded:Connect(function(player)
      player.CharacterAdded:Connect(function(character)
             local humanoid = character:FindFirstChild("Humanoid")
             humanoid.Seated:Connect(function()
                         character.HumanoidRootPart.Position = seatBrick.Position + Vector3.new(0,1,0)
                         humanoid.WalkSpeed = 0
                         end)
                end)
end)
2 Likes

Yeah but how would I use it in a proximity prompt script for a specific seat?

1 Like

In the .Seated function, you’re able to obtain the seat that the character references. Let me see if I can write something up for you.

2 Likes

So, like

local seat = whatever you use to find it

if seat.name = “the name” then

1 Like

No no no, you’re able to do:

humanoid.Seated:Connect(function(isSeated, seat)
                         print(seat) -- THIS WILL GIVE YOU THE SEAT PART. So, you can check:
                         if seat.Name == "Whatever" then

                         character.HumanoidRootPart.Position = seatBrick.Position + Vector3.new(0,1,0)
                         humanoid.WalkSpeed = 0
                         end
 end)
2 Likes

Thanks
But how do I make the GUI and script apply for the occupant?

1 Like

In proximity prompts, you’re able to get the player for the 2nd parameter.

local function onPromptTriggered(whatever, player)
       local playerGui = player.PlayerGui
end
1 Like

I think you can do something like this (regualr script in the seat)

local seat = script.Parent
local prompt = seat.ProximityPrompt
local plrs = game:GetService("Players")
local GuiToClone = --Your Gui you want to display

prompt.Triggered:Connect(function(plr)
	local char = plr.Character
	seat:Sit(char.Humanoid)
	prompt.Enabled = false
end)

local formerPlayer

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant
	if hum then
		local player = plrs:GetPlayerFromCharacter(hum.Parent)
		prompt.Enabled = false
		GuiToClone:Clone().Parent = player.PlayerGui
		formerPlayer = player
	else
		formerPlayer.PlayerGui[GuiToClone.Name]:Destroy()
		prompt.Enabled = true
		formerPlayer = nil
	end
end)

Put the ScreenGui containing everything you want to display to who is sitting where you want and change local GuiToClone = to include the location of the gui

@WarioSvug It’s okay! You can still help if you’d like! And don’t worry, maybe in the future you’ll become my level as well!

9 Likes

Embat is better than me so listen to them ^ lmao.

1 Like

I tested it, It works, but what about the controller script?

Where is it located? In the ScreenGui?

Its located in the Seat, Userinputservice fires a remote event

Simply find the seat and the UI and clone it and put it in the playerGui folder within the player.

I think you could do this to also enable the controller

local seat = script.Parent
local controller = seat.ControllerScript
local prompt = seat.ProximityPrompt
local plrs = game:GetService("Players")
local GuiToClone = --Your Gui you want to display

prompt.Triggered:Connect(function(plr)
	local char = plr.Character
	seat:Sit(char.Humanoid)
end)

local formerPlayer

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant
	if hum then
		local player = plrs:GetPlayerFromCharacter(hum.Parent)
		local plrgui = player.PlayerGui
		prompt.Enabled = false
		GuiToClone:Clone().Parent = plrgui
		local controllerClone = controller:Clone()
		controllerClone.Parent = plrgui
		controllerClone.Disabled = false
		formerPlayer = player
	else
		local plrgui = formerPlayer.PlayerGui
		plrgui[GuiToClone.Name]:Destroy()
		plrgui[controller.Name]:Destroy()
		prompt.Enabled = true
		formerPlayer = nil
	end
end)

Just replace ControllerScript with the name of the controller script, make sure it’s disabled at first

So heres my changed version of your script

local seat = script.Parent
local controller = seat.ControllerScript
local prompt = seat.ProximityPrompt
local plrs = game:GetService("Players")
local GuiToClone = script.Parent.ScreenGui

	prompt.Triggered:Connect(function(plr)
	local char = plr.Character
	seat:Sit(char.Humanoid)
	prompt.Enabled = false
	controller.Disabled = false
end)

local formerPlayer

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant
	if hum then
		local player = plrs:GetPlayerFromCharacter(hum.Parent)
		local plrgui = player.PlayerGui
		prompt.Enabled = false
		GuiToClone:Clone().Parent = plrgui
		local controllerClone = controller:Clone()
		controllerClone.Parent = plrgui
		controllerClone.Disabled = false
		formerPlayer = player
	else
		local plrgui = formerPlayer.PlayerGui
		plrgui[GuiToClone.Name]:Destroy()
		plrgui[controller.Name]:Destroy()
		prompt.Enabled = true
		formerPlayer = nil
	end
end)

Then my controller script (local script)

local usp = game:GetService(“UserInputService”)
local enginefireupevent = script.Parent:WaitForChild(“Idle”)

usp.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType then
if input.Keycode == Enum.KeyCode.E then
enginefireupevent:FireServer()
print(“Engine Fired Up!”)
end
end
end)

then my event script:
–Events

local enginefireupevent = Instance.new(“RemoteEvent”)

enginefireupevent.Parent = script.Parent.Parent

enginefireupevent.Name = “Idle”

enginefireupevent.OnServerEvent:Connect(function(fireup)

print(“Engine Started”)

end)

But it doesnt work, No errors, can you try to fix it?