Group rank button with proximity prompt

G’day, I need help with a script.
I made a train game divided into classes and to open the doors of the first class carriages you have to be part of a rank in the group. The buttons to open the doors use the proximity prompt. How can I make a button that, based on rank, opens the door?

1 Like

You could use Player:GetRankInGroup() to make it.
Here is an example with a ClickDetector;

local groupId = -- your group id here!
local part = script.Parent

part.ClickDetector.MouseClick:Connect(function(plr)
	local plrRank = plr:GetRankInGroup(groupId)
	
	if plrRank == 254 or plrRank == 255 then -- If player is ranked at 254 or 255.
		print("Hello admin.")
		-- do stuff
	elseif plrRank == 0 then -- If player not on group it will be 0.
		print("Not in group.")
		-- do stuff
	end
	
end)
1 Like

Something like that

local GroupId = 0
local RankId = 0
local ProximityPrompt = script.Parent

function OpenDoor()

end

ProximityPrompt.Triggered:Connect(function(player)
	if player:GetRankInGroup(GroupId) == RankId then
		OpenDoor()
	end
end)
1 Like
local Prompt = script.Parent

local ProtectedCall = pcall
local GroupId = 0
local GroupRank = 0

Prompt.Triggered:Connect(function(Player)
	local Success, Result = ProtectedCall(function()
		return Player:GetRankInGroup(GroupId)
	end)
	
	if Success then
		if Result >= GroupRank then
			--Code here is executed if the player meets the group rank requirement.
		else
			Player:LoadCharacter() --Respawns player's character if the group rank requirement isn't met.
		end
	end
end)

You may want to switch “==” into “>=” such that if the player exceeds the required group rank the action, in this context the call to the function “OpenDoor()” still takes place.

3 Likes