Owner Only Proximity Prompt For Vehicle

Hello, I am looking to create an aircraft, where the pilot seat would be entered with a Proximity Prompt. I wish for the proximity prompt to only be usable by the owner (determined by stringvalue), and not allow anyone with a different username to use the seat.

Currently, the prompt can be used by anyone, regardless of whether or not they are the owner

So far, I have this script:

local ProximityPrompt = script.Parent
local seat = ProximityPrompt.Parent
local owner = game.Workspace.OwnerValue.Value
seat.Disabled = true
ProximityPrompt.RequiresLineOfSight = false

ProximityPrompt.Triggered:Connect(function(player)
	seat.Disabled = false
	local charecter = workspace:WaitForChild(player.Name)
	if player.Name == owner then
		local humanoid = charecter.Humanoid
		seat:Sit(humanoid)
		ProximityPrompt.Enabled = false
		while seat.Occupant do
			wait()
		end
	else
		ProximityPrompt.Enabled = true
		seat.Disabled = true
	end
	ProximityPrompt.Enabled = true
	seat.Disabled = true
end)

I searched through about two dozen other posts and solutions on here, however none seem to work. Thank you.

4 Likes

you should move the line local owner = game.Workspace.OwnerValue.Value inside the Triggered event.

2 Likes

Have done so, there is no difference.

1 Like

May i ask if you’re checking the player by UserId or Username?

1 Like

Currently checking owner by username.

1 Like

i assume he is using an id to determine if hes the owner.
i recommend trying

ProximityPrompt.Triggered:Connect(function(player)
	local owner = game.Workspace.OwnerValue.Value
	if owner then
		print("Owner: " .. owner)
	else
		print("Owner not found")
		return
	end

to see if it does consider you owner

3 Likes

im unsure if checking by username would stunt your script but your userID can never change

1 Like

Tested this system with both Owner ID and Username. It prints the value of the string value, but does not determine whether or not the owner was the one interacting with the prompt.

1 Like

I edited some things in the script. Check if this works:

local Game_Workspace = game:GetService("Workspace")
local ProximityPrompt = script.Parent
local Seat = ProximityPrompt.Parent
local Owner = Game_Workspace:WaitForChild("OwnerValue")
ProximityPrompt.RequiresLineOfSight = false
Seat.Disabled = true

ProximityPrompt.Triggered:Connect(function(player)
	Seat.Disabled = false
	local character = Game_Workspace:FindFirstChild(player.Name)
	if player.Name == Owner.Value then
		local humanoid = character.Humanoid
		Seat:Sit(humanoid)
		ProximityPrompt.Enabled = false
		while Seat.Occupant do
			task.wait()
		end
	else
		ProximityPrompt.Enabled = true
		Seat.Disabled = true
	end
	ProximityPrompt.Enabled = true
	Seat.Disabled = true
end)
5 Likes

Tried this script, however it does not recognize anyone as the owner at all. I added a print function to your script, and it keeps returning “Not Owner”.

local Game_Workspace = game:GetService("Workspace")
local ProximityPrompt = script.Parent
local Seat = ProximityPrompt.Parent
local Owner = Game_Workspace:WaitForChild("OwnerValue")
ProximityPrompt.RequiresLineOfSight = false
Seat.Disabled = true

ProximityPrompt.Triggered:Connect(function(player)
	Seat.Disabled = false
	local character = Game_Workspace:FindFirstChild(player.Name)
	if player.Name == Owner.Value then
		print("Owner")
		local humanoid = character.Humanoid
		Seat:Sit(humanoid)
		ProximityPrompt.Enabled = false
		while Seat.Occupant do
			task.wait()
		end
	else
		print("Not Owner")
		ProximityPrompt.Enabled = true
		Seat.Disabled = true
	end
	ProximityPrompt.Enabled = true
	Seat.Disabled = true
end)
2 Likes

Are you sure you have the correct spelling and capitalization of your username on the OwnerValue?

Sorry for the trouble, the reason for your script not working was due to me accidentally misplacing it. The current system is functional, Thank you for your help!

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