I need assistance with scripting a way for a serverside script (the code below) to activate a local script to make it so that player in any seat of a given vehicle will not see other proximity prompts while driving or sitting in a passenger seat. Or any other way that is more efficient.
SERVER-SIDE SCRIPT
local proximityPromt = script.Parent
local seat = proximityPromt.Parent
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
proximityPromt.Enabled = false
-- possibly could add a proximitypromt.Localscript.Disabled = false?
else
proximityPromt.Enabled = true
-- possibly could add a proximitypromt.Localscript.Disabled = true?
end
end)
proximityPromt.Triggered:Connect(function(player)
seat:Sit(player.Character.Humanoid)
end)
Trying to decide the most efficient and optimized way to use a system for multiple different vehicles, players, and teams. To access the vehicle that they spawned in, not have somebody take it, not see the other prompts beside them to enter the said vehicle, and for it to have the option to exclude certain teams from accessing a vehicle that would be for example: “A normal officer cannot access a Federal Bureau of Investigation vehicle.”
Side note: I’m new to scripting so if the answer is obvious please tell me
local function OnPromptTriggered(Player)
local Character = Player.Character
if not Character then return end
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if not Humanoid then return end
if Humanoid.SeatPart then return end --Is sitting.
end
Prompt.Triggered:Connect(OnPromptTriggered)
whenever they activate the proximity prompt to sit just add a local script into their character or backpack. this will automatically make the local script run. this can be done through cloning a local script that hasn’t activated yet
make sure to have an object value as a child of the local script and assign the value to the vehicle’s model
have another bool value as a child of the local script call it whatever, something that saids delete.
on the server script where ever the occupant changed connection is to set the delete bool value to true (add a fail safe just in case the local script got disabled, aka pcall a function to delete it after a certain time)
inside the local script:
loop through object value’s value to look for all proximity prompts
for each one set their enabled to false
whenever the delete bool value gets set to true call a function to to the same things above just setting enabled to true (unless someone is already sitting in it)
i would give you code example but formatting on phone is hard. if you need further explanation tell me