Hello, very simple to understand, i have a car that has 4 seats and when you enter all the proximityprompts hide so you can see it better and not accidentally sit in another seat, but i forgot that doing that on a regular script would hide all the proximityprompts for everyone, so no one could longer enter in the car unless the person exits the car, any ideas for hiding the proximity prompt only for the player sitting? aka locally?
ive tried this script on the startercharacterscripts, but i had this error
for _, seat in pairs(workspace.Vehicles:GetDescendants()) do
if seat:IsA("Seat") or ("VehicleSeat") then
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
if proximityPrompt:IsA("ProximityPrompt") then
proximityPrompt.Enabled = false
end
end
else
for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
if proximityPrompt:IsA("ProximityPrompt") then
proximityPrompt.Enabled = true
end
end
end
end)
end
end
driver seat proximity prompt script (there is one inside each seat)
local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent
local fr_pp = seat.Parent.Body.Seat.SeatFR.ProximityPrompt
local rl_pp = seat.Parent.Body.Seat.SeatRL.ProximityPrompt
local rr_pp = seat.Parent.Body.Seat.SeatRR.ProximityPrompt
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
proximityPrompt.Enabled = false
else
proximityPrompt.Enabled = true
end
end)
proximityPrompt.Triggered:Connect(function(player)
if player.Character.Humanoid.Sit == false then
seat:Sit(player.Character.Humanoid)
end
end)
Make sure to verify who is sitting since the event is being made for every client, maybe you can probably do something like this
local player = game:GetService("Players").LocalPlayer
for _, seat in pairs(workspace.Vehicles:GetDescendants()) do
if seat:IsA("Seat") or seat:IsA("VehicleSeat") then
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local humanoid = seat.Occupant
if not player.Character or (humanoid and not humanoid:IsDescendantOf(player.Character) then
return
end
if seat.Occupant then
for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
if proximityPrompt:IsA("ProximityPrompt") then
proximityPrompt.Enabled = false
end
end
else
for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
if proximityPrompt:IsA("ProximityPrompt") then
proximityPrompt.Enabled = true
end
end
end
end)
end
end
The only issue I may say is that if anyone gets off a seat it may make every prompt visible again. So I think ytou’d have to make a variable to store the previous person who sat down and when there’s no occupant, reference that variable
yea just saw that im testing here with local server then i entered the vehicle with both players and i left with the passenger one, and the proximityprompts appeared again
local player = game:GetService("Players").LocalPlayer
local formerOccupant
for _, seat in pairs(workspace.Vehicles:GetDescendants()) do
if seat:IsA("Seat") or seat:IsA("VehicleSeat") then
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local humanoid = seat.Occupant
local playerHumanoid = humanoid or formerOccupant
if not player.Character or (playerHumanoid and not playerHumanoid:IsDescendantOf(player.Character) then
return
end
if humanoid then
for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
if proximityPrompt:IsA("ProximityPrompt") then
proximityPrompt.Enabled = false
end
end
formerOccupant = humanoid
else
for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
if proximityPrompt:IsA("ProximityPrompt") then
proximityPrompt.Enabled = true
end
end
formerOccupant = nil
end
end)
end
end
i will try that, so i would make the script on the serverscriptservice, then 2 remoteevents to toggle on and off, and when the humanoid is sitting toggle it off and when not toggle it on?
You only need 1 remoteevent for toggling, but you just give it the state yourself, if you want to toggle the prompts to on, pass in true, else pass in false
RemoteEvent.OnClientEvent:Connect(function(state)
--Codee
end)
--And somewhere else in a server script
RemoteEvent:FireClient(player, true)
--State would be true when the event is fired
local storage = game:WaitForChild("ReplicatedStorage")
local event = storage:WaitForChild("ProximityPrompts")
local formerOccupant
local function ToggleOnOff()
for _, seat in pairs(workspace.Vehicles:GetDescendants()) do
if seat:IsA("Seat") or seat:IsA("VehicleSeat") then
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local player = game:GetService("Players"):GetPlayerFromCharacter(seat.Occupant.Parent)
local humanoid = seat.Occupant
local playerHumanoid = humanoid or formerOccupant
if not player.Character or (playerHumanoid and not playerHumanoid:IsDescendantOf(player.Character)) then
return
end
if humanoid then
for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
if proximityPrompt:IsA("ProximityPrompt") then
proximityPrompt.Enabled = false
end
end
formerOccupant = humanoid
else
for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
if proximityPrompt:IsA("ProximityPrompt") then
proximityPrompt.Enabled = true
end
end
formerOccupant = nil
end
end)
end
end
end
event.OnServerEvent:Connect(ToggleOnOff())
local script
local player = game:GetService("Players").LocalPlayer
local storage = game:WaitForChild("ReplicatedStorage")
local event = storage:WaitForChild("ProximityPrompts")
for _, seat in pairs(workspace.Vehicles:GetDescendants()) do
if seat:IsA("Seat") or seat:IsA("VehicleSeat") then
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
event:FireClient(player, true)
end
end)
end
end