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

How to find a player's rank using GetRankInGroup on a SurfaceGUI Button?

How would you use GetRankInGroup to find a players rank using a SurfaceGui Button?

I would like it so that it is used within a "if" function that I am doing.

player = game.Players.PlayerAdded
loading = false

script.Parent.MouseButton1Down:connect(function()
	if loading == false then
		loading = true
		print("Login")
		script.Parent.Text = ("Logging In")
		wait(0.5)
		script.Parent.Text = ("Logging In.")
		wait(0.5)
		script.Parent.Text = ("Logging In..")
		wait(0.5)
		script.Parent.Text = ("Logging In...")
		wait(0.5)
		script.Parent.Text = ("Logging In")
		wait(0.5)
		script.Parent.Text = ("Logging In.")
		wait(0.5)
		script.Parent.Text = ("Logging In..")
		wait(0.5)
		if player:GetRankInGroup(731703).Value == true then
			script.Parent.Text = ("Access Accepted")
			wait(2)
			script.Parent.Text = ("Welcome!")
			wait(1)
			game.ServerStorage.TerminalData.Host.Value = true
			script.Parent.Text = ("Click To Login")
			loading = false
		else
			script.Parent.Text = ("Access Denied")
			wait(2)
			script.Parent.Text = ("Click To Login")
			loading = false
		end
	end
end)

2 answers

✓ Accepted answer

Is this was you needed?

I don't know where this script is running so you need to add in the player instance

e.g:-

script.parent.parent

to get the player rank:-

rank = "player instance":GetRankInGroup( --group id here)

GetRankInGroup

12 comments

0

I will try it!

0

Where would the instance usualy be?

0

Where is this script running? and what method is being triggered? e.g Touched:connect()

0

Script is running like so Workspace,TerminalSystems,Terminal,Screen,SurfaceGUI,Frame,Button,script.(Really far!). I want it trigged as in a button on the screen..

0

1st you need to add in the button click event if you have not allready done it http://wiki.roblox.com/index.php?title=API:Class/GuiButton/MouseButton1Click

0

2nd add this line in print(script.parent) add .parent until the player name is displayed e.g print(script.parent.parent)

0

I done that, Let me get the script on the page.

0

3rd add this plr = game.Players:GetPlayerFromCharacter( all of the code inside the brackets of the print function) This will return a player instance which can be used with the code above

0

OK

0

just in case you dont know but to show the output window you need to go to view->output

0

That is easy. I know how to script, just could not figure out how to find the player and GetRankInGroup. I usualy do it through a part.

0

Thanks!

The code below will check if a player that has entered the game has a rank equal to 255, in a group with an ID of 2. If they are, it will print "Player is the owner of the group, 'LOL'!", otherwise "Player is NOT the owner of the group, 'LOL'!" will be printed to the output.

game.Players.PlayerAdded:connect(function(Player)
    if Player:GetRankInGroup(2) == 255 then
        print("Player is the owner of the group, 'LOL'!")
    else
        print("Player is NOT the owner of the group, 'LOL'!")
    end
end)
Alternatively, you could use ternary operators to make the code shorter.

game.Players.PlayerAdded:connect(function(Player)
    local Rank = Player:GetRankInGroup(2)
    print("Player is "..(Rank == 255 and "" or "NOT").." the owner of the group 'LOL'!")
end)

Source here - http://wiki.roblox.com/index.php?title=API:Class/Player/GetRankInGroup

2 comments

0

I did say. Within an If function. This function is not the one I wanted.

0

There is no 'if' function unless you make one. You mean conditional

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