Okay, so, I have this script (server script, put in ServerScriptService) that changes the player’s humanoid display name if they have a minium rank on a group. It doesn’t work at all, this is my script:
local char = player.Character
local humanoid = char:FindFirstChildOfClass('Humanoid')
if player:GetRankInGroup(16003890) >= 254 then
player:LoadCharacter()
humanoid.DisplayName = "[👑]"..humanoid.DisplayName
end
end)
When you call :LoadCharacter(), you’re essentially just respawning the character. This doesn’t invalidate the variables you have though, so it won’t necessarily error, but the references you have won’t be current (the Humanoid in the humanoid variable simply references the humanoid in the removed character). Getting rid of player:LoadCharacter() should fix the problem.
It also could be a race condition, where the humanoid or character isn’t present when the code runs.
Instead of this:
local char = player.Character
local humanoid = char:FindFirstChildOfClass('Humanoid')
Try this:
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:FindFirstChildOfClass('Humanoid') or char:WaitForChild("Humanoid")
Finished code:
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:FindFirstChildOfClass('Humanoid') or char:WaitForChild("Humanoid")
if player:GetRankInGroup(16003890) >= 254 then
humanoid.DisplayName = "[👑]"..humanoid.DisplayName
end