Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Myaxp 3
9 years ago

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

Log in to vote
0
Answered by 9 years ago

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

0
I will try it! Myaxp 3 — 9y
0
Where would the instance usualy be? Myaxp 3 — 9y
0
Where is this script running? and what method is being triggered? e.g Touched:connect() User#5423 17 — 9y
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.. Myaxp 3 — 9y
View all comments (8 more)
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 User#5423 17 — 9y
0
2nd add this line in print(script.parent) add .parent until the player name is displayed e.g print(script.parent.parent) User#5423 17 — 9y
0
I done that, Let me get the script on the page. Myaxp 3 — 9y
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 User#5423 17 — 9y
0
OK Myaxp 3 — 9y
0
just in case you dont know but to show the output window you need to go to view->output User#5423 17 — 9y
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. Myaxp 3 — 9y
0
Thanks! Myaxp 3 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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

0
I did say. Within an If function. This function is not the one I wanted. Myaxp 3 — 9y
0
There is no 'if' function unless you make one. You mean conditional DigitalVeer 1473 — 9y

Answer this question