I'm having trouble getting the assigned rank to show on a gui. I need help. I currently have this, and it continues down till i have all the ranks
local groupId = 956931 function onPlayerSpawned(player) if player:GetRankInGroup(groupId) == 1 then script.Parent.header.TextLabel.Text = "Rank: Trainee" end end function onPlayerSpawned(player) if player:GetRankInGroup(groupId) == 2 then script.Parent.header.TextLabel.Text = "Rank: Suspended" end end
There are a few problems.
Problem 1
The functions aren't being called, they are just being defined. When a function is defined, it does not run (example #1).
Also, since by default, GUIs load every time a player spawns, your functions are not needed because they will only need to run once (example #2).
As well as that, you don't need to make heaps of different functions (example #3)
Example #1
function printText(text) -- this won't work, because it needs to be called print(text) end printText("yes") -- prints the text
-- something similar to what you were attempting to do function playerAdded(plr) print(plr.Name.. " has joined the game!") end game.Players.PlayerAdded:connect(playerAdded) -- calls the function whenever a player joins
Example #2
-- script inside GUI local group_id = 0000 local player = game.Players.LocalPlayer -- this only works in a LocalScript local header = script.Parent:WaitForChild("header") -- so it doesn't try to index something that has not loaded yet local rank = player:GetRankInGroup(group_id) if rank == 1 then header.Text = "Rank: Trainee" end
Example #3
function spawned() if rank == 1 then -- code elseif rank == 2 then -- notice the elseif -- code end end
Useful link for if statements: https://www.youtube.com/watch?v=7aEa6MDNaCs
Problem #2
You can easily get a player's rank name in a certain group using this function:
player:GetRoleInGroup(group_id) -- returns a string, which you can put in a Text object
Hope I helped! Note that I am in a rush, so there may be some errors or discrepancies here and there.
~TDP
This is just a second answer to your latest problem. TDP's answer was amazing.
local group_id = 956931 local player = game.Players.LocalPlayer local header = script.Parent:WaitForChild('header') local rank = player:GetRankInGroup(group_id) if rank == 1 then header.TextLabel.Text = 'ranknamehere' elseif rank == 2 then head.TextLabel.Text = 'ranknamehere' elseif rank == 14 then head.TextLabel.Text = 'ranknamehere' end
The PlayerAdded event you were attempting to use would not work, as the current player would have gone into the game, then the scripts would have loaded. Meaning the player would join, the scripts would load the second after the player joins, which does not trigger the PlayerAdded
event. You don't even need that considering that you already had player defined. I may have mistyped something incorrectly, but before you comment 'it doesn't work', please double check to make sure that you can't fix it, and there's nothing in the console about the script. If you can't find the error, then say "It doesn't work", and I will help you to the best of my ability.