Proximity prompt issue

Greetings.

I scripted a Bench where you can sit and everything is fine.
The only issue is that when I was testing with my friend, we found out that whenever you sit using the proximity prompt, the proximity that activates after which is the one that teleports you away is usable by players that are not sitting aswell, which makes it possible for them to click and get teleported but to trap the other player in the seat. I want to make a local proximity prompt that ONLY the person sitting can see. Can anyone help me doing that? Thank you!


script.Parent.Parent.Parent.Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if script.Parent.Parent.Parent.Seat.Occupant then
		script.Parent.Enabled = false
	else
		script.Parent.Enabled = true
        workspace.Bench.PromptExit1.ProximityPrompt.Enabled = false
	end
end)

script.Parent.Triggered:Connect(function(plr)
	script.Parent.Parent.Parent.Seat:Sit(plr.Character.Humanoid)
	script.Parent.Enabled = false

	wait(1)
	
	workspace.Bench.PromptExit1.ProximityPrompt.Enabled = true

end)
1 Like

You can add a variable that checks if there is a player sitting and restricts them from triggering the action exclusively. This is just an example so you can get a background on how it would work.

local playerSit = nil

script.Parent.Parent.Parent.Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if script.Parent.Parent.Parent.Seat.Occupant then
		script.Parent.Enabled = false
		playerSit = script.Parent.Parent.Parent.Seat.Occupant
	else
		script.Parent.Enabled = true
		playerSit = nil
		workspace.Bench.PromptExit1.ProximityPrompt.Enabled = false
	end
end)

script.Parent.Triggered:Connect(function(plr)
	if not playerSit then
		script.Parent.Parent.Parent.Seat:Sit(plr.Character.Humanoid)
		script.Parent.Enabled = false

		wait(1)

		workspace.Bench.PromptExit1.ProximityPrompt.Enabled = true
	end
end)

Another example pertains to the Bench Proximity Prompt. When triggered, it allows you to check if the player is currently sitting. If the player is not sitting, the prompt will refrain from teleporting the player.

2 Likes

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