Heyo everyone!
Currently at my game, a few players (really a minority but its still making server errors)
are getting Infinite Yield on WaitForChild() of my RankContainer.
This is the code:
local Players = game:GetService("Players")
local Overhead = script:WaitForChild("PlayerOverhead")
local Ranks = require(script:WaitForChild("Ranks"))
local OwnerId = 2641744211
local function EditPlayerRank(Player: Player, Overhead: BillboardGui)
local leaderstats = Player:FindFirstChild("leaderstats")
if leaderstats then
local RankContainer = Overhead:WaitForChild("RankContainer", 60)
if not RankContainer then
warn("RankContainer not found in Overhead for player " .. Player.Name)
return
end
local RankLabel = RankContainer:FindFirstChild("RankLabel")
if not RankLabel then
warn("RankLabel not found in RankContainer for player " .. Player.Name)
return
end
if Player.UserId == OwnerId then
RankLabel.Text = "Owner"
local CurrentGradient = RankLabel:FindFirstChildOfClass("UIGradient")
if CurrentGradient then
CurrentGradient:Destroy()
end
local ColorGradient = script.RanksGradients:FindFirstChild("Owner")
if ColorGradient then
RankLabel.TextColor3 = Color3.new(1, 1, 1)
ColorGradient:Clone().Parent = RankLabel
else
RankLabel.TextColor3 = Color3.new(0, 0, 0)
end
else
for _, RankInfo in ipairs(Ranks) do
if leaderstats["Purchases"].Value >= RankInfo.Purchases and leaderstats["R$ Spent"].Value >= RankInfo.Spent then
RankLabel.Text = RankInfo.Rank
local CurrentGradient = RankLabel:FindFirstChildOfClass("UIGradient")
if CurrentGradient then
CurrentGradient:Destroy()
end
local ColorGradient = script.RanksGradients:FindFirstChild(RankInfo.Rank)
if ColorGradient then
RankLabel.TextColor3 = Color3.new(1, 1, 1)
ColorGradient:Clone().Parent = RankLabel
else
RankLabel.TextColor3 = Color3.new(0, 0, 0)
end
break
end
end
end
end
end
local function InsertOverhead(Player: Player, Character: Model)
local newOverhead = Overhead:Clone()
newOverhead.Parent = workspace[Player.Name].Head
--newOverhead.Adornee = Target
newOverhead.NameContainer.NameLabel.Text = Player.DisplayName or Players.Name
EditPlayerRank(Player, newOverhead)
local leaderstats = Player:FindFirstChild("leaderstats")
leaderstats["Purchases"].Changed:Connect(function()
EditPlayerRank(Player, newOverhead)
end)
leaderstats["R$ Spent"].Changed:Connect(function()
EditPlayerRank(Player, newOverhead)
end)
end
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
task.wait(3)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.ChildAdded:Connect(function(Child)
if Child:IsA("HumanoidDescription") then
InsertOverhead(Player, Character)
end
end)
InsertOverhead(Player, Character)
end)
end)
I can’t figure out what else to do. I even made a check, after the issues were occuring, to give me a warning on what player its not finding RankContainer.
I have to mention that my game is around Outfits, and I might think this is related to that, when a player wears an outfit, the humanoidDescription is changed, which can change the head. However, at the end of the script, that is already checked, and it works for most players.
All the childs exist, everything works perfectly for most players (including myself) so I can’t figure out why its warning for this minority.
Can this be related to Ping/Device not being able to inset the Overhead GUI? Should I ignore it, since it doesn’t affect most players, or try to fix it?
Thanks!