My code was always working before, After a month i came back to an old project and it gave me an error i never had seen before.
It is inside a normal script for reasons.
The code may be a bit messy but i just don’t understand it.
local Character = OverheadGuiObject.Parent
local plr = game:GetService("Players"):GetPlayerFromCharacter(Character)
local GroupID = 7628430
local GetRankInGroup = plr:GetRoleInGroup(GroupID) -- This line.
local InGroup = plr:IsInGroup(GroupID) -- Also this line.
Your issue could be that the script is running before the character itself has loaded. You can approach this with a few different methods.
.1) Simply add a task.wait(1) (Not the most reliable)
.2) Use a loop:
local plr = game:GetService("Players"):GetPlayerFromCharacter(Character)
while not plr do
Character = OverheadGuiObject.Parent
plr = game:GetService("Players"):GetPlayerFromCharacter(Character)
task.wait(.1)
end
This will keep attempting to get a player based off OverheadGuiObject’s Parent by constantly updating the variables till it exists. So this could be an infinite yield theoretically.
If its inside StarterCharacterScripts you Can get the plr by game.Players.LocalPlayer
local plr = game:GetService("Players").LocalPlayer
local Character = plr.Character
local GroupID = 7628430
local GetRankInGroup = plr:GetRoleInGroup(GroupID) -- This line.
local InGroup = plr:IsInGroup(GroupID) -- Also this line.
--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
--// Variables
local GroupRoles = require(ReplicatedStorage.Modules.Group.Ranks)
local OverheadGuiObject = script.Parent
local PlrNameText = OverheadGuiObject.PlayerName
local Character = OverheadGuiObject.Parent
local plr = game:GetService("Players"):GetPlayerFromCharacter(Character)
print(plr)
local GroupID = 7628430
local GetRankInGroup = plr:GetRoleInGroup(GroupID)
local InGroup = plr:IsInGroup(GroupID)
--// Functions
OverheadGuiObject.Parent = Character.Head
PlrNameText.RichText = true
PlrNameText.TextColor3 = Color3.fromRGB(255, 255, 255)
if InGroup then
PlrNameText.Text = GroupRoles.Overhead_GroupRanks()[GetRankInGroup] .. plr.Name
else
PlrNameText.Text = [[<font color="rgb(238, 196, 182)"> [Guest] </font>]] .. plr.Name
end
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
Humanoid.NameDisplayDistance = 0
while RunService.Heartbeat:Wait() do
for i, v in pairs(OverheadGuiObject:GetChildren()) do
local success, err = pcall(function()
if v.Name ~= "Player" and v.ClassName == "TextLabel" then
v.Font = "Bodoni"
local Stats = plr:WaitForChild("Stats")
if v.Name == "Cash" then
v.Text = v.Name .. ": $" .. Stats.Cash.Value
end
end
end)
end
end
local success, error = pcall(function()
local Character = OverheadGuiObject.Parent
local plr = game:GetService("Players"):GetPlayerFromCharacter(Character)
local GroupID = 7628430
local Role = plr:GetRoleInGroup(GroupID) -- This line.
print(plr.Name, GroupID, Role)
end)
if not success then
warn(error)
end
I’m printing all your data, if it doesn’t print, something is wrong with your GroupID. Also, IsInGroup should mostly be used for if statements!