How can I make proximity prompt certain ranks only?

I currently have proximity prompt doors that teleport you from one place to another. Currently, I am looking for a way to make the proximity prompt visible to only certain ranks. Does anyone know how to do this?

This is the current script and what it does:

local Settings = script.Parent.Parent.Settings
local object = Settings:FindFirstChild("TpPart") -- getting the tppart object value
local Animation = Settings:FindFirstChild("Animation") -- if its set to true then there will be an animation when Teleporting

local Remote = game.ReplicatedStorage.GuiAnimate

function tp(char)
	if object and object.Value then -- if the ObjectValue exist we run the code
		if game.Players:GetPlayerFromCharacter(char) then -- making sure its a player
			char:MoveTo(object.Value.CFrame * Vector3.new(0,3,0))
		end
	else
		-- printing an error to the output when the object value doesnt exist
		error("Object doesn't exist or not found or value is empty from Settings > Tp Part")
	end
end

script.Parent.Triggered:Connect(function(trigger)
	local char = trigger.Character or trigger.CharacterAdded:Wait() -- getting the triggerer character
		
	if char then -- if the character existff
		if Animation and Animation.Value == true then
			local position = object.Value.Position
			
			Remote:FireClient(trigger, object.Value)
		else
			tp(char) -- the vector is where it adds 3 studs from the y value so that it doesnt stick to the ground
		end
	end
end)

I’ve looked for solutions on DevForum, but I haven’t found anything that works with my script.

One way to go about this would be creating the proximity prompt from the client if the player meets the requirements. You can then listen to the Triggered event and fire a remote event.
For security reasons, you have to check if the player actually meets the requirements on the server aswell. If so, you can proceed to teleport them:

-- From a LocalScript:
local player = game.Players.LocalPlayer

local groupId = 0 -- GroupId here
local requiredRankId = 0 -- Required RankId here 

local success, result = pcall(player.GetRankInGroup, player, groupId)

if success then
	if result >= requiredRankId then
		local proximityPrompt = Instance.new("ProximityPrompt")
--		... set the proximity prompt up
		proximityPrompt.Triggered:Connect(function()
			game.ReplicatedStorage.ProximityPromptTriggered:FireServer()
		end)
	end
end
-- From a ServerScript:
local requiredRankId = 0 -- Required RankId here

game.ReplicatedStorage.ProximityPromptTriggered.OnServerEvent:Connect(function(player)
	local success, result = pcall(player.GetRankInGroup, player, groupId)
	if success then
		if result >= requiredRankId then
--			... player is eligible to be teleported
		end
	end
end)

(I have not tested this.)

2 Likes

That makes sense to how it would work, but sadly it doesn’t. I tried changing a few things to make it work, but nothing worked. Thanks for the suggestion!

What are you struggling with? Are you receiving any errors?

Sorry for the late reply. No, I’m not. When I try and change my current script to add rank permissions, it just doesn’t work.