Problems with UI on reset

local function Update(user)
	Level.Text = user.Level
	ExpLabel.Text = user.Exp .. ' / 100'
	print(ExpLabel, ExpBar, ExpBar.BarExp) -- prints ExpLabel ExpBar BarExp
	ExpBar.BarExp.Text = ExpLabel.Text
	
	ExpBar:TweenSize(UDim2.new(user.Exp / 100, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1, true)
end

DataUpdated.OnClientEvent:Connect(Update)

BarExp is not a valid member of Frame

Not sure why this is occuring when my player resets. Works on join, but after resetting I get that error.

HUD is set to ResetOnSpawn true (NOT GONNA CHANGE!!)

Don’t quote me on this, but I heard somewhere on here that Gui replication isn’t exactly the best. Maybe try using the WaitForChild method on ExpBar to reference BarExp.

Seemed to fix that line, but now the second line aint working :confused:

 -- this line
ExpBar:TweenSize(UDim2.new(user.Exp / 100, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1, true)

Can only tween objects in the workspace

Apparently when using ResetOnSpawn the reference becomes outdated. I’d try referencing the GuiObjects in the Update function if you haven’t already.

Do I have to reference every element again then?

local TopControl = {}

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local Remotes = ReplicatedStorage:WaitForChild('Remotes')
local Events = Remotes:WaitForChild('Events')
local DataUpdated = Events:WaitForChild('DataUpdated')

local Frame = script.Parent

local ExpHolder = Frame:WaitForChild('ExpHolder')
local LevelHolder = Frame:WaitForChild('LevelHolder')

local ExpBar = ExpHolder:WaitForChild('ExpBar')
local ExpLabel = ExpHolder:WaitForChild('ExpLabel')

local BarExp = ExpBar:WaitForChild('BarExp')

local Level = LevelHolder:WaitForChild('Level')

ExpLabel.Size = UDim2.new(0, ExpHolder.AbsoluteSize.X, 0.75, 0)
BarExp.Size = UDim2.new(0, ExpHolder.AbsoluteSize.X, 0.75, 0)

local function Update(user)
	local Frame = script.Parent
	local ExpHolder = Frame:WaitForChild('ExpHolder')
	local LevelHolder = Frame:WaitForChild('LevelHolder')

	local ExpBar = ExpHolder:WaitForChild('ExpBar')
	local ExpLabel = ExpHolder:WaitForChild('ExpLabel')

	local BarExp = ExpBar:WaitForChild('BarExp')

	local Level = LevelHolder:WaitForChild('Level')
	
	Level.Text = user.Level
	ExpLabel.Text = user.Exp .. ' / 100'
	BarExp.Text = ExpLabel.Text
	
	ExpBar:TweenSize(UDim2.new(user.Exp / 100, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1, true)
end

DataUpdated.OnClientEvent:Connect(Update)

return TopControl

This happens sometimes when a GUI is not parented to anything. Where is your script and is it still in the place it should be when the player re-spawns?

For the objects in the Gui, I’d assume so.

Script is a module inside a frame. it gets required by a LocalScript that requiers all the HUD elements

Seems a littl weird :confused: don’t see why it needs to be so hacky