ProximityPrompt for Specific Person Only

Hello

I have this garage door right here, pretty simple with a tween playing when someone activates it.

It’s part of a Suburban Home I built, and I want to rent that out. Hence I want only the owner of the House to be able to open the door. I just don’t know how.

Script:

local TS = game:GetService("TweenService")
local Part = script.Parent
local prox = Part.ProximityPrompt
local proxTriggered = 0
local function OpenTween()
	local info = TweenInfo.new(
		0.2,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.In,
		0,
		false,
		0
	)
	
	local goals =
	{
			Transparency = 1,
			CanCollide = false
	}
	
		local tween = TS:Create(Part, info, goals)
		
		tween:Play()
end
local function CloseTween()
	local info = TweenInfo.new(
		0.2,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.In,
		0,
		false,
		0
	)
	
	local goals =
	{
			Transparency = 0,
			CanCollide = true
	}

	local tween = TS:Create(Part, info, goals)
	tween:Play()
end

prox.Style = Enum.ProximityPromptStyle.Default
prox.HoldDuration = 0.2
prox.ActionText = "Open"
prox.ObjectText = "Door"
prox.Triggered:Connect(function()
	proxTriggered = proxTriggered + 1
	if proxTriggered == 1 then
		prox.ActionText = "Close"
		OpenTween()
	elseif proxTriggered > 1 then
		prox.ActionText = "Open"
		proxTriggered = 0
		CloseTween()
	end
end)

Though I am doofus at scripting, maybe I have to check the UserID and then proceed with the script and tween playing itself?

Thanks for any tip…

PS: As I said, I’m still learning scripting, so please, try to make the tips noob friendly :slight_smile:

I would create the Proximity Prompt under a LocalScript so that the only person with the Proximity Prompt is the Owner. Create the ProximityPrompt when the Player Buys the home.

1 Like

The player doesn’t buy the house in game, it’s made over my communications server

I also need the door the open visibly to everyone else in the Server, I don’t think a LocalScript does that?

You could check if the player who is using the prompt is the Owner of the house. Like this:

prox.Triggered:Connect(function(player) -- Player is the Player that used the Proximity Prompt
    if player.Name == OwnerOfHouse then
        -- open the door
    end
end)
1 Like

OwnerOfTheHouse is just the UserID of the owner, right?

The name of the Owner, but if you wanted it to be UserID, you would do:

prox.Triggered:Connect(function(player) -- Player is the Player that used the Proximity Prompt
    if player.UserId == OwnerOfHouse then
        -- open the door
    end
end)
1 Like


It also underlines Prox at the very beginning of the script

Also if it interests you:
q

I don’t see any issues, but make sure that the
prox.Triggered:Connect(function()
turns into
prox.Triggered:Connect(function(player)

1 Like

I think the issue lies with the 2 ends at the very bottom, they are marked red

(And yes, the player appears after the function you mentioned:
prox.Triggered:Connect(function(player) )

I think you are missing one end somewhere, make sure you didn’t forget one.

1 Like

a

Where am I supposed to put one? I’m sorry for asking lol

No its ok, I think higher up in your script is where there needs to be an end. Can you show me your entire script?

1 Like

Fixed it, the red lines are gone:
Screenshot 2022-10-16 153639

1 Like

Now it still underlines the “Prox”

You defined prox as a variable after that. You need to define the proximity prompt higher up in your script. Also, make sure it is ‘prox’ not ‘Prox’

1 Like

Higher? I can’t go higher than that, it’s already the top of the script? I think I know what you mean, but at the same time I don’t

It should be like this:

local TS = game:GetService("TweenService")
local Part = script.Parent
local prox = Part.ProximityPrompt
local ProxTriggered = 0

prox.Triggered:Connect(function(player)
    -- your script
end)

The way you currently have it, you are trying to call the variable “prox” before you have defined it. It is like doing this:

print(x)
local x = 'hi'

This doesn’t work, because you print the variable before you define it.

1 Like

Okay, I tried to define it, but it underlines that part that the Prox is in as red??

Copy this exactly and place it at the top of your script:

local TS = game:GetService("TweenService")
local Part = script.Parent
local prox = Part.ProximityPrompt
local ProxTriggered = 0
1 Like

Okay I’ve NEVER seen this before: