Exception while signaling: Must be a LuaSourceContainer

Currently re-writing how things are done for my player’s UI and I’ve been getting the title’s error for the past few days.

It mostly happens once the player reach about 50-60% of his experience bar progress.

It doesn’t stop the script from running at all and everything works despite printing quite a lot of those.

Any feedback or insight would be appreciated.

-- Important --
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local pUI = script.Parent
local Abb = require(game.ReplicatedStorage.ShortenNumber)

-- Stats -- 
local pStats = player.PlayerData:WaitForChild("Stats")
local pExp = pStats:WaitForChild("EXP")
local pMaxEXP = pStats:WaitForChild("MaxEXP")
local pStamina = pStats:WaitForChild("Stamina")
local pMaxStamina = pStats:WaitForChild("MaxStamina")
local pLevel = pStats:WaitForChild("Level")
local LevelNumber = pUI:WaitForChild("Level")
local uiGold = pUI:WaitForChild("Gold")
local vGold = player.PlayerData.Wallet:WaitForChild("Gold")

-- UI --

local pUI = script.Parent

local HealthBG = pUI:WaitForChild("Health")
local HealthBar = HealthBG:WaitForChild("Bar")
local HealthDamage = HealthBG:WaitForChild("Damage")
local HealthNumber = HealthBG:WaitForChild("Number")

local StaminaBG = pUI:WaitForChild("Stamina")
local StaminaBar = StaminaBG:WaitForChild("Bar")
local StaminaDamage = StaminaBG:WaitForChild("Damage")
local StaminaNumber = StaminaBG:WaitForChild("Number")

local EXPBG = pUI:WaitForChild("EXP")
local EXPBar = EXPBG:WaitForChild("Bar")
local EXPDamage = EXPBG:WaitForChild("Damage")
local EXPNumber = EXPBG:WaitForChild("Number")


-- Variables --
local LevelNumber = pUI:WaitForChild("Level")



local function healthChanged()
	local pHealth = hum.Health
	local pMaxHealth = hum.MaxHealth
	local hp = pHealth / pMaxHealth
	local hpText = ("%i%%"):format(hp * 100.00)

	HealthNumber.Text = "HEALTH: "..hpText
	HealthBar:TweenSize(UDim2.fromScale(hp, 1), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.15, true)
	delay(0.5, function()
		HealthDamage:TweenSize(UDim2.fromScale(hp, 1), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.15, true)
	end)
end

local function expChanged()
	local xp = pExp.Value / (pLevel.Value * 25)
	local xpText = ("%i%%"):format(xp * 100.00)
	
	local levelText = pLevel.Value

	EXPNumber.Text = "EXP: "..xpText
	
	LevelNumber.Text = "LEVEL: "..levelText

	EXPDamage:TweenSize(UDim2.fromScale(xp, 1), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.15, true)
	
	delay(0.5, function()
		EXPBar:TweenSize(UDim2.fromScale(xp, 1), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.15, true)
	end)
end

local function goldChanged()
    pcall(function()
        vGold.Changed:Connect(function()
            local gold = vGold.Value
            uiGold.Text = "$" ..Abb.Abb2(gold)
        end)
    end)
end




local function staminaChanged()
	local sta = pStamina.Value / pMaxStamina.Value
	local staText = ("%i%%"):format(sta * 100.00)

	StaminaNumber.Text = "STAMINA: "..staText

	StaminaBar:TweenSize(UDim2.fromScale(sta, 1), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.15, true)
	
	delay(0.5, function()
		StaminaDamage:TweenSize(UDim2.fromScale(sta, 1), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.15, true)
	end)
end

healthChanged()
expChanged()
staminaChanged()
goldChanged()

hum:GetPropertyChangedSignal("Health"):Connect(healthChanged)
pExp:GetPropertyChangedSignal("Value"):Connect(expChanged)
pStamina:GetPropertyChangedSignal("Value"):Connect(staminaChanged)
vGold:GetPropertyChangedSignal("Value"):Connect(goldChanged)

player.CharacterAdded:connect(function(character)
	healthChanged()
	expChanged()
	staminaChanged()
	goldChanged()
end)

This error message indicates that the code is trying to use a value that is not a LuaSourceContainer , but it is expecting it to be. In other words, the code is trying to use a value as if it were a LuaSourceContainer object, but the value is not actually an instance of that type.

In this specific code, the error seems to be occurring in the goldChanged function. This function is attempting to connect to the Changed event on the vGold variable, which is supposed to be a Value object. However, if vGold is not actually a Value object, then the code will throw this error when it tries to connect to the Changed event.

To fix this issue, you should verify that the vGold variable is indeed a Value object before attempting to connect to its Changed event. This can be done with a simple if statement, for example:

local function goldChanged()
    if typeof(vGold) == "Value" then
        vGold.Changed:Connect(function()
            local gold = vGold.Value
            uiGold.Text = "$" ..Abb.Abb2(gold)
        end)
    end
end

This will check the type of vGold before trying to connect to the Changed event, and only do so if vGold is indeed a Value object. This should prevent the error from occurring.

I do not know if this is the root cause, or if this will fix it, but i hope it helps with anything!

This error has been going on even before I add the “gold” value into the UI handler
I’m fairly sure it’s related to the EXP part which I’m quite unsure what’s the root cause as it doesn’t stop the script at all :sweat_smile:

I am sorry I couldn’t find the cause.

I suggest adding checks, handling the errors with the pcall function, and more.