I’m stumped because this code should work just fine. I cannot imagine why this code would not work. I’ll use ChatGPT once again to add print statements throughout the module, and you can tell me which parts are having problems.
ModuleScript
local overheadModule = {}
local playersService = game:GetService('Players')
local commasModule = require(script.Parent:WaitForChild('Commas'))
local overheadGuiObject = script:WaitForChild('display')
local function getLeaderboardValue(player, name)
return player.leaderstats[name]
end
local associatedGuiObjects = {} -- { [number]: { overheadGuiObject: BillboardGui, character: Model } }
function overheadModule:Create(player: Player)
if associatedGuiObjects[player.UserId] then
print("GUI already exists for player:", player.Name)
return
end
local character = player.Character
if typeof(character) == 'Instance' then
local head = character:WaitForChild('Head', 5)
if typeof(head) == 'Instance' and head:IsA('BasePart') then
local playerStrengthValue = select(2, pcall(getLeaderboardValue, player, 'Strength'))
if typeof(playerStrengthValue) == 'Instance' then
local overheadGui = overheadGuiObject:Clone()
overheadGui.Nickname.Text = player.DisplayName
overheadGui.StrengthDisplay.Text = commasModule(playerStrengthValue.Value) .. ' Strength'
overheadGui.Parent = character:FindFirstChild('Head')
associatedGuiObjects[player.UserId] = { character = character, overheadGuiObject = overheadGui }
print("Created overhead GUI for player:", player.Name)
else
print("Failed to get Strength value for player:", player.Name)
end
local humanoid = character:FindFirstChildWhichIsA('Humanoid')
if typeof(humanoid) == 'Instance' then
humanoid.NameDisplayDistance = 0
end
else
print("Player", player.Name, "is missing Head part, skipping.")
end
else
print("Player", player.Name, "does not have a character, skipping.")
end
end
function overheadModule:Hide(player: Player)
local character = player.Character
local guiObjectEntry = associatedGuiObjects[player.UserId]
if type(guiObjectEntry) == 'table' and typeof(character) == 'Instance' and guiObjectEntry.character == character then
guiObjectEntry.overheadGuiObject.Enabled = false
print("Hidden overhead GUI for player:", player.Name)
end
end
local function getStrengthDisplay(character)
return character.Head.display.StrengthDisplay
end
function overheadModule.UpdateStrengthText(player: Player)
print("Updating strength text for player:", player.Name)
local character = player.Character
if typeof(character) == 'Instance' then
print("Player character found:", character)
local textLabel = select(2, pcall(getStrengthDisplay, character))
print("Strength display retrieved:", textLabel)
local playerStrength = select(2, pcall(getLeaderboardValue, player, 'Strength'))
print("Player strength retrieved:", playerStrength)
if typeof(textLabel) == 'Instance' and typeof(playerStrength) == 'Instance' then
print("Updating text label with strength value:", playerStrength.Value)
textLabel.Text = commasModule(playerStrength.Value) .. ' Strength'
else
print("Invalid textLabel or playerStrength type.")
end
else
print("Invalid character type for player:", player.Name)
end
print("Update complete for player:", player.Name)
end
return overheadModule
Server Script
local playersService = game:GetService('Players')
local replicatedStorage = game:GetService('ReplicatedStorage')
local overheadModule = require(replicatedStorage:WaitForChild('overHeadModule'))
local updateOverheadEvent = replicatedStorage:WaitForChild('updateOverhead')
playersService.PlayerAdded:Connect(function(player: Player)
print('PlayerAdded event triggered for player:', player.Name)
local strengthValue = player:WaitForChild('leaderstats'):WaitForChild('Strength')
local function loadCharacter(character: Model)
print('loadCharacter function called for player:', player.Name)
if typeof(character) == 'Instance' then
print('Creating overhead for player:', player.Name)
overheadModule:Create(player)
if typeof(strengthValue) == 'Instance' and strengthValue:IsA('ValueBase') then
print('Strength value is valid for player:', player.Name)
strengthValue:GetPropertyChangedSignal('Value'):Connect(function(...: any)
print('Strength value changed for player:', player.Name)
overheadModule.UpdateStrengthText(player)
end)
else
print('Could not validate the strength value for player:', player.Name, 'because it is either not an instance or a value.')
end
end
end
pcall(loadCharacter, player.Character)
player.CharacterAdded:Connect(function()
print('CharacterAdded event triggered for player:', player.Name)
loadCharacter(player.Character)
end)
end)
As always, double check if the code does not meet your standards, and be cautious of AI generated code. I have explicity told it to only add print statements for diagnosis.