Group Rank+ Seat that kicks

So I want to make a seat that kicks you if are not group rank+, how would I do that?

Kicks you off of the seat, or kicks you from the game?

example of a script that will kick you from the game:

local RankRequired = ("rank you want")
local groupid = yourgroupid

Seat.Touched:Connect(function(hit)
local player = game.Players:FindFirstChild(hit.Parent.Name)
if player then
local Rank = player:GetRoleInGroup(groupid)
if Rank ~= RankRequired then
player:Kick("You are not (rank)!")
end
end
end)
1 Like

To add onto that, if you want a script that will simply kick them out of the seat and not the whole game:

local RankRequired = ("rank you want")
local groupid = yourgroupid
local Seat = script.Parent

Seat.Touched:Connect(function(hit)
	local player = game.Players:FindFirstChild(hit.Parent.Name)
	if player then
		local Rank = player:GetRoleInGroup(groupid)
		if Rank ~= RankRequired then
			Seat.Disabled = true
			wait(0.5)
			Seat.Disabled = false
		end
	end
end)

(And make sure you put the script inside of the seat)

1 Like

Thank you for the help. -Developer NorthernTaticaI

1 Like

Thank you for the help, and adding on the script. -Developer NorthernTaticaI

1 Like

Ideally for something like this you would do the following, however, it can be done using multiple methods. This example would be far better on performance than the code posted above.

local Seat = script.Parent

local GROUP_ID = 0
local ROLE_REQUIRED = ""

local cacheResults = true
local roleCache = {}

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local humanoid = Seat.Occupant
	if humanoid then
		local character = humanoid.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		if player then
			local roleInGroup = cacheResults and roleCache[player] or player:GetRoleInGroup(GROUP_ID)
			roleCache[player] = roleCache
			if roleInGroup ~= ROLE_REQUIRED then
				humanoid.Jump = true
			end
		end
	end
end)

-- To avoid a memory leak
game.Players.PlayerRemoving:Connect(function(player)
	roleCache[player] = nil
end)

In the example we’re only checking when the seat’s Occupant property is changed, which contains the Humanoid that is sitting on the seat, we can then fetch the role of the user and store it in a table to avoid making further requests and speeding up the processing time. If you want to make it so that players without the role don’t automatically get seated you can disable the seat and manually call the :Sit() method. If you are going to be using multiple seats I would highly suggest looking into CollectionService to make a better system.

Ok, I will try that being I am not that great of a programmer I am not real good at understanding the code.