Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Get player rank from HD Admin?

I have this function in a script that allows the player to bypass the anti-exploit if it returns true.

local function HasAdmin(id)
	for i = 1,#Administrators do
		if (string.upper(id) == string.upper(Administrators[i])) then 
			return true 
		end
	end 
	local player = game.Players:GetNameFromUserIdAsync(id)
	if game.Workspace:FindFirstChild(player) then
		if game.Workspace:FindFirstChild(player).Humanoid.Health < 5 then
			return true
		end
	end
	local checkModule = require(script.CheckRank)
	
	checkModule.checkRank(player) -- tried a module script bc all of the HD admin scripts were inside modules (idk how use modules. this might be wrong o-o)
	

--[[ First attempt. Didn't work 

	local main = _G.HDAdminMain
	local plrRank = main.pdata[player].Rank
	if plrRank >= 1.5 then
		return true
	end
]]


	return false 
end

I want it so if the players rank is higher than something then it will return true. This is what I have in my module script.

local module = {}

local main = _G.HDAdminMain

function module:checkRank(player)
	local plrRank = main.pdata.Rank
	if plrRank >= 1.5 then
		return true
	end
	return false
end



return module

Error: ServerScriptService.Anti-Exploit.MuffinHacks.CheckRank:6: attempt to index nil with 'Rank'

Image: https://cdn.discordapp.com/attachments/789594500922081320/839367100506308608/yudduly.PNG

1 answer

I have looked through the code of HDAdmin. One reason your script isn't working is because your script runs before _G assign HDAdminMain to the MainFramework, and also because the data for the server is stored in main.pd[player]

local module = {}	 

function module:checkRank(player)
	local main = _G.HDAdminMain
	local plrRank = main.pd[player].Rank
	print(plrRank) -- Prints 5 for owner
	if plrRank >= 1.5 then
		return true
	end
	return false
end
 
return module

3 comments

0

uh does it need to be in the function or somethin? it still error right when I join and after hd icon loads.

0

A better way would be to get the _G.HDAdminMain inside the checkRank function so that when you run the function, it's gonna get the HDAdminMain inside the function and then by the time, you run the function, _G would have loaded the variables, and not when the module is required. I have edited the script

0

Also, pretty sure that it's main.pd[player] on the server, and main.pdata on the client. Cannot confirm since I don't use HD Admin anymore

This discussion is preserved as it was. New answers, comments, and votes are closed.