Hello, I want to create a system that makes only certain player could it by pressing on the Proximity Prompt. I am using this script that I got from developer.roblox.com as a code sample. Thank you.
local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent.VehicleSeat
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
proximityPrompt.Enabled = false
else
proximityPrompt.Enabled = true
end
end)
proximityPrompt.Triggered:Connect(function(player)
seat:Sit(player.Character.Humanoid)
end)
1 Like
You can add a variable that tells which player is allowed:
local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent.VehicleSeat
local AllowedPlayer = "" -- Put the player that is allowed here
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.DisplayName == AllowedPlayer then
seat:Sit(player.Character.Humanoid)
end
end)
1 Like
I would say to instead replace “DisplayName” to “Name” just so that we don’t have 2 Sams trying to sit in 1 seat.
Since DisplayNames are out now, a lot of people will use their DisplayName. Plus, the DisplayName is what you will see first in game. I think the best option is to use Player.UserId instead.
Ah yes, I agree. All 3 are viable solutions.
So, do I do it like this?
local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent
local AllowedPlayer = Player.UserId = "1890669972" -- Put the player that is allowed here
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.DisplayName == AllowedPlayer then
seat:Sit(player.Character.Humanoid)
end
end)
Because a UserId is a number, you don’t need to put quotation marks around it. Also, instead of checking for the DisplayName, you should check for the UserId. It would look something like this:
local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent
local AllowedPlayer = 1890669972 -- Put the player's UserId that is allowed here
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.UserId == AllowedPlayer then
seat:Sit(player.Character.Humanoid)
end
end)
2 Likes
Oh, I realized something. I can’t enter the Seat, is it because I just put my UserId? Thank you. 
Can you not enter the seat from the ProximityPrompt or from touching the seat?
I can’t enter the seat from doing the Proximity Prompt.
Are there any errors in the Output?
Sorry for the late reply, I will check and inform you.
There aren’t any errors for the script.
I don’t know why it wouldn’t be working. I’ve made a model for you to use. See if it works. Seat - Roblox
1 Like
Thanks for making a model for me to use
, but I actually figured out a working script right now.
local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent
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.UserId == 1890669972 then
seat:Sit(player.Character.Humanoid)
end
end)
1 Like