I’m trying to create a script for an application center that kicks the player if they are not a specific rank in the group. The script works but I want to add more to the kick message, I’m trying to make it so that the kick message tells the player their rank in the group but I don’t know how to get the group rank ID into the name of the group rank.
local plr = game:GetService("Players")
local groupId = 10074000
plr.PlayerAdded:Connect(function(player)
wait(0.5)
if player:GetRankInGroup(groupId) == 2 then
script:Destroy()
else
player:Kick("This application is only available to Clearance Level 0, your current rank is " ..player:GetRankInGroup(groupId)..".")
end
end)
I am aware I don’t need this, I just want to learn how it would be done since I’m still learning Lua.
You can just use :GetRoleInGroup to get the string of their role name:
--//Services
local Players = game:GetService("Players")
--//Controls
local GroupId = 10074000
--//Functions
Players.PlayerAdded:Connect(function(player)
task.wait(0.5)
local playerRank = nil
local success, errorMessage = pcall(function()
playerRank = player:GetRoleInGroup(GroupId)
end)
if not success or not playerRank then
warn(errorMessage)
player:Kick("An error has occurred, please join later.")
return
end
if playerRank == 2 then
script:Destroy()
else
player:Kick("This application is only available to Clearance Level 0, your current rank is ".. player:GetRoleInGroup(GroupId) ..".")
end
end)
Or if you’re looking for custom titles, you can try this:
--//Services
local Players = game:GetService("Players")
--//Controls
local GroupId = 10074000
--//Tables
local RoleTitles = {
[6] = "random guy",
[255] = "cool guy",
}
--//Functions
Players.PlayerAdded:Connect(function(player)
task.wait(0.5)
local playerRank = nil
local success, errorMessage = pcall(function()
playerRank = player:GetRoleInGroup(GroupId)
end)
if not success or not playerRank then
warn(errorMessage)
player:Kick("An error has occurred, please join later.")
return
end
if playerRank == 2 then
script:Destroy()
else
local roleName = RoleTitles[playerRank]
player:Kick("This application is only available to Clearance Level 0, your current rank is ".. roleName ..".")
end
end)
I suggest wrapping those calls in a pcall, to prevent issues when the web is down.
local success,result = pcall(function()
return player:GetRoleInGroup(GroupId)
end)
if success then
if result == 2 then
script:Destroy()
else
local roleName = RoleTitles[result]
player:Kick("This application is only available to Clearance Level 0, your current rank is ".. roleName ..".")
end
end