Disabling Proximity Prompts Locally

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!
    I have some proximity prompts that make the player sit on the corresponding seats of a helicopter. While it works fine, the issue is that when the player is already sitting in a seat, the proximity prompt for the other seat shows.

Driver prompt visible while in passenger seat:

Passenger prompt visible while in driver seat:

if I disable it through the same server script then it would hide it for all players, meaning that another player wont be able to get in the other seat.

is there a way to hide the prompt locally so that other players can still see and interact with?

.

2 Likes

You gotta detect seat occupant and disable the prompts if someone is seated. You also need to detect if the local player is already seated, which disables all seat prompts. Use a client-sided script to connect all of the seats and prompts.

Would this in a StarterPlayer local scipt be enough?

local player = game:GetService("Players").LocalPlayer
local char = player.CharacterAdded:Wait()
local human = char:WaitForChild("Humanoid")

human.Seated:Connect(function(active)
	for _, part in workspace:GetDescendants() do
		if part:IsA("ProximityPrompt") then
			part.Enabled = not active
		end
	end
end)
1 Like

you can create a condition to check if the player is already sitting in a seat before displaying the proximity prompt for the other seat.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local seat1 = -- seat1
local seat2 = -- seat2

local function isPlayerSitting()
    return seat1:IsPointInSeat(humanoidRootPart.Position) or seat2:IsPointInSeat(humanoidRootPart.Position)
end

local function onPromptAction(trigger)
    if not isPlayerSitting() then
        if trigger == seat1.ProximityPrompt then
            --logic for sitting on seat1 here
        elseif trigger == seat2.ProximityPrompt then
            -- Make the player sit on seat2
            if humanoidRootPart:FindFirstChild("SeatWeld") == nil then
                local seatWeld = Instance.new("SeatWeld")
                seatWeld.Part0 = humanoidRootPart
                seatWeld.Part1 = seat2.Seat
                seatWeld.Name = "SeatWeld"
                seatWeld.C0 = CFrame.new(0, 0, 0) 
                seatWeld.Parent = humanoidRootPart
            end
        end
    end
end

seat1.ProximityPrompt.Triggered:Connect(function()
    onPromptAction(seat1.ProximityPrompt)
end)

seat2.ProximityPrompt.Triggered:Connect(function()
    onPromptAction(seat2.ProximityPrompt)
end)


so basically this code checks if Character is already sitting, and hide the Prompts

is this in local or server script? if its in a server wouldn’t it hide it for all players?

LocalScript, for client side.

you can place the LocalScript inside a player’s character or backpack

you will need to connect to when the player sits, then you can simply do this:

local ProximityPromptService = game:GetService(“ProximityPromptService”)
if Humanoid.Sit then ProximityPromptService.Enabled = false end

That would work but he wants it to be disabled only for the local player.

That’s why you would do that in a client script?

1 Like

Example StarterPlayerScripts localscript implementation

local ProximityPromptService = game:GetService("ProximityPromptService")
local Player = game.Players.LocalPlayer
local Humanoid

local function handleSit()
	if Humanoid and Humanoid.Sit then
		ProximityPromptService.Enabled = false
	else
		ProximityPromptService.Enabled = true
	end
end

local function handleCharacterAdded(character)
	local Character = character
	Humanoid = Character:WaitForChild("Humanoid")
	Humanoid:GetPropertyChangedSignal("Sit"):Connect(handleSit)
end

Player.CharacterAdded:Connect(handleCharacterAdded)
if Player.Character then
	handleCharacterAdded(Player.Character)
end

1 Like

After some modifications it works perfectly now

here’s the script in case anyone needs it:

--place in StarterPlayerScripts
local player = game:GetService("Players").LocalPlayer
local char = player.CharacterAdded:Wait()
local human = char:WaitForChild("Humanoid")
local ProximityPromptService = game:GetService("ProximityPromptService")

human.Seated:Connect(function(active)
	ProximityPromptService.Enabled = not active
end)
2 Likes

You are correct, i forgot that StarterPlayer and StarterCharacter ran the scripts diffently, here the new version that work with starterCharacter:

local char = script.Parent
local human = char:WaitForChild("Humanoid")
local ProximityPromptService = game:GetService("ProximityPromptService")

human.Seated:Connect(function(active)
	ProximityPromptService.Enabled = not active
end)
1 Like

Deleted my comment because I needed to test before being so sure haha. But yeah, that one looks better :slight_smile:
Also very cool flight system!

1 Like

your assumption was correct, after resetting the character it stopped working.

Also thanks!

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