Overhead gui leaderstats value not updating

problem is overhead gui leaderstats value not updating like in the top

im making a overhead gui for my simulator and im not very experienced with overhead guis so i dont really know how to fix this.

any help is appreciated and also thanks ahead

im prolly jsut stupid tbh

the print(update) dosent register jsuk

heres my modulescript in replicated storage

local ps = game:GetService("Players")
local commasModule = require(game.ReplicatedStorage.Commas)
local overHeadGuiObject = script.display

local overHeadModule = {}

function overHeadModule:Create(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	
	local playerStrength = Player:WaitForChild("leaderstats"):FindFirstChild("Strength")
	
	local Clone = overHeadGuiObject:Clone()
	Clone.Nickname.Text = Player.DisplayName
	Clone.StrengthDisplay.Text =  commasModule(playerStrength.Value).. " Strength"
	Clone.Parent = Character.Head

	Character.Humanoid.NameDisplayDistance = 0
end

function overHeadModule:Hide(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()

	Character.Head.overHeadGuiObject.Enabled = false
end

overHeadModule.UpdateStrengthText = function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local textlabel = character:WaitForChild("Head").display:FindFirstChild("StrengthDisplay")
	local playerStrength = player:WaitForChild("leaderstats"):FindFirstChild("Strength")
	textlabel.Text = commasModule(playerStrength.Value).. " Strength"
end

return overHeadModule

heres my server script in serverscriptservice

local ps = game:GetService("Players")
local overHeadModule = require(game:GetService("ReplicatedStorage").overHeadModule)
	
local remote = game.ReplicatedStorage.updateOverhead

ps.PlayerAdded:Connect(function(Player)
	print("player added make player strength reference")
	local strength = Player:WaitForChild("leaderstats")['Strength']

	Player.CharacterAdded:Connect(function(Character)
		print("character added create billboard")
		overHeadModule:Create(Player)

		strength:GetPropertyChangedSignal('Value'):Connect(function()
			print("update")
			overHeadModule.UpdateStrengthText(Player)
		end)
	end)
end)
1 Like

i’m not sure what tyhe commas module is however I would think that its having some kind of issue with adding an integer to a string? so you may have to do:

overHeadModule.UpdateStrengthText = function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local textlabel = character:WaitForChild("Head").display:FindFirstChild("StrengthDisplay")
	local playerStrength = player:WaitForChild("leaderstats"):FindFirstChild("Strength")
	textlabel.Text = tostring(playerStrength.Value).. " Strength"
end

If I’m wrong about that can you explain what the commas module thing is?

the commas module will make the numbers go from 1000 to 1,000 as example

function comma_value(amount)
	local formatted = amount
	while wait() do
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)","%1,%2")
		if (k==0) then
			break
		end
	end
	return formatted
end

return comma_value
1 Like

the update strength text module works just in the server script it wont execute it when the value is changed and the way if found that out was the print(update wasnt running) so u have any idea how to fix that?

You may need to check if the values you are accessing are available, particularly the values that are essential for anything to work. I’ve done this assessment by writing implementations of type checking into the overhead module.

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
		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 }
			end
			
			local humanoid = character:FindFirstChildWhichIsA('Humanoid')
			if typeof(humanoid) == 'Instance' then
				humanoid.NameDisplayDistance = 0
			end
		end
	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
	end
end

local function getStrengthDisplay(character)
	return character.Head.display.StrengthDisplay
end

function overheadModule.UpdateStrengthText(player: Player)
	local character = player.Character
	if typeof(character) == 'Instance' then
		local textLabel = select(2, pcall(getStrengthDisplay, character))
		local playerStrength = select(2, pcall(getLeaderboardValue, player, 'Strength'))
		
		if typeof(textLabel) == 'Instance' and typeof(playerStrength) == 'Instance' then
			textLabel.Text = commasModule(playerStrength.Value) .. ' Strength'
		end
	end
end

return overheadModule

Feel free to add print statements where you believe the issue may be occurring.


Now about the second script, where you have a RemoteEvent declared, I assume you want to connect something to it? Maybe there’s something we’re not seeing in this code yet.

Now you can do the same here, and you can add your print statements to find the issue throughout the code but for the most part this is all original code with a few tweaks to the code to account for type-checking, and even storing overheadGui objects in an array with an associated character to help you keep track of who’s overhead GUI belongs to who.

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)
	local strengthValue = player:WaitForChild('leaderstats'):WaitForChild('Strength')

	local function loadCharacter(character: Model)
		if typeof(character) == 'Instance' then
			overheadModule:Create(player)
			strengthValue:GetPropertyChangedSignal('Value'):Connect(function(...: any)
				overheadModule.UpdateStrengthText(player)
			end)
		end
	end
	
	pcall(loadCharacter, player.Character)
	player.CharacterAdded:Connect(loadCharacter)
end)

Above is the second script in which I’ve done about the same thing in terms of type-checking.

Here’s something we can take away from this:

  • You should always utilize the methods provided by the Instance class when necessary
    • This includes using WaitForChild, FindFirstChild, FindFirstAncestor and their sister methods.
  • It’s crucial to use proper error-handling techniques, such as the pcall function, to gracefully handle potential errors and prevent the entire script from breaking.
    • If you don’t want to handle the error, just call the method; it takes the function as the first argument, and everything after that is the arguments to pass to the function being called.

Let me know if you have any questions.

1 Like

this still for some reason wont go through

strengthValue:GetPropertyChangedSignal('Value'):Connect(function(...: any)
				print("updating strength Value")
				overheadModule.UpdateStrengthText(player)
			end)

Is there an error associated with the problem you are having? If there is no problem, you should try using the Changed event instead. If you are running in a different context from your intended context (Server, Client, etc.) I’d just like to mention I’ve had issues in the past where LocalScripts don’t listen to events retrieved from GetPropertyChangedSignal properly.

Let me know more about where this script is located, and what class this script is.

1 Like

dosent work with .Changed either

the server script is located in server script service and the module script is located in replicated storage

Is strengthValue a valid Instance in this case, then? You can check using the typeof function, and if it is a string result of “Instance”, then you should check if it’s IsA method result is a “ValueBase”

For example:

if typeof(strengthValue) == 'Instance' and strengthValue:IsA('ValueBase') then

else
    print('Could not validate the strength value because it is either not an instance or a value.')
end
1 Like

where should i put this in the scripts? updatestrengthtext or overhead:create thing

This should go in your server script in this connection:

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)
	local strengthValue = player:WaitForChild('leaderstats'):WaitForChild('Strength')

	local function loadCharacter(character: Model)
		if typeof(character) == 'Instance' then
			overheadModule:Create(player)
			if typeof(strengthValue) == 'Instance' and strengthValue:IsA('ValueBase') then
				strengthValue:GetPropertyChangedSignal('Value'):Connect(function(...: any)
					overheadModule.UpdateStrengthText(player)
				end)
			else
				print('Could not validate the strength value because it is either not an instance or a value.')
			end
		end
	end

	pcall(loadCharacter, player.Character)
	player.CharacterAdded:Connect(loadCharacter)
end)
1 Like

it didnt print anything so thats not the error

Okay, I see… This may be due to the UpdateStrengthText function not working as expected. Let’s add some print statements to help diagnose the issue:

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

Keep in mind that I prompted ChatGPT for this code and explicity told it to add descriptive print statements throughout the code without changing the functionality. Conversation can be found here.

1 Like

so whats happening here is the

function overheadModule.UpdateStrengthText(player: Player)

is not even being called none of the printments are in the output

That’s something I’ve never encountered before, which is weird and new to me. I believe this may have something to do with your leaderstats folder or it’s configuration. Where are you creating the leaderboard and the associated statistics for it?

Are you getting any warnings other than errors in your output? I’d be worried about anything that mentions an infinite yield because the new code I have provided uses the WaitForChild method several times.

1 Like

i havent got any errors

im creating my leaderstats in serverscriptservice

here it is if u want to take a look at it

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local hiddenvalues = Instance.new("Folder")
	hiddenvalues.Name = "hiddenValues"
	hiddenvalues.Parent = player
	
	local strength = Instance.new("IntValue")
	strength.Name = "Strength"
	strength.Value = 0
	strength.Parent = leaderstats
	
	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Value = 0
	wins.Parent = leaderstats
	
	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Value = 0
	rebirths.Parent = leaderstats
	
	local gain = Instance.new("NumberValue")
	gain.Name = "Gain"
	gain.Value = 1
	gain.Parent = hiddenvalues
	
	local petsmax = Instance.new("IntValue")
	petsmax.Name = "petsMaxEquipped"
	petsmax.Value = 8
	petsmax.Parent = hiddenvalues
	
	local petsequipped = Instance.new("IntValue")
	petsequipped.Name = "petsEquipped"
	petsequipped.Value = 0
	petsequipped.Parent = hiddenvalues
	
	local petsamount = Instance.new("IntValue")
	petsamount.Name = "petsAmount"
	petsamount.Value = 0
	petsamount.Parent = hiddenvalues
	
	local petstrength = Instance.new("NumberValue")
	petstrength.Name = "petStrength"
	petstrength.Value = 1
	petstrength.Parent = hiddenvalues
	
	local winsgain = Instance.new("NumberValue")
	winsgain.Name = "winsGain"
	winsgain.Value = 1
	winsgain.Parent = hiddenvalues
	
	local petsgainmultiplier = Instance.new("IntValue")
	petsgainmultiplier.Name = "petsGainMultiplier"
	petsgainmultiplier.Value = 0
	petsgainmultiplier.Parent = hiddenvalues
	
	local winsneededforrebirth = Instance.new("IntValue")
	winsneededforrebirth.Name = "winsNeededForRebirth"
	winsneededforrebirth.Value = 100
	winsneededforrebirth.Parent = hiddenvalues
end)

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.

1 Like
  20:18:32.899  PlayerAdded event triggered for player: kattenemil2017  -  Server - overhead:8
  20:18:33.869  Animation Spoofer cannot run while game is running  -  Client
  20:18:33.936  loadCharacter function called for player: kattenemil2017  -  Server - overhead:13
  20:18:34.608  CharacterAdded event triggered for player: kattenemil2017  -  Server - overhead:32
  20:18:34.608  loadCharacter function called for player: kattenemil2017  -  Server - overhead:13
  20:18:34.608  Creating overhead for player: kattenemil2017  -  Server - overhead:15
  20:18:34.641  Created overhead GUI for player: kattenemil2017  -  Server - overHeadModule:32
  20:18:34.641  Strength value is valid for player: kattenemil2017  -  Server - overhead:19

Alright, now what in your game actually applies a new value to the strength value? Can you test something to see if the value actually gets changed? Make sure that the value is being accessed correctly through player.leaderstats.Strength.

1 Like

here is my gain script which applies the strength and ive seen in my leaderstats folder the value is getting changed also in my strength display

local player = game.Players.LocalPlayer
local clicksound = script.sound
local msp = game:GetService("MarketplaceService")
local debounce = true

game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end

	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if debounce then
			debounce = false

			local petsGainMultiplier = player:WaitForChild("hiddenValues"):WaitForChild("petsGainMultiplier")
			local strength = player:WaitForChild("leaderstats"):WaitForChild("Strength")
			local strengthGain = player:WaitForChild("hiddenValues"):WaitForChild("Gain")
			
			local petStrength = player:WaitForChild("hiddenValues"):FindFirstChild("petStrength")

			local gain = strengthGain.Value + (petsGainMultiplier.Value * petStrength.Value)

			if msp:UserOwnsGamePassAsync(player.UserId, 667278112) then
				strength.Value = strength.Value + (gain * 2)-- Double the gain
			else
				strength.Value = strength.Value + gain -- Regular gain
			end

			clicksound:Play()
			wait(0.085)
			debounce = true
		end
	end
end)