You can write your topic however you want, but you need to answer these questions:
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?
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)
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
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
--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)
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)