PlayerGui TextLabel not updating?

Hello,

I am having an issue with displaying a gun’s ammo. I have a screen gui with a text label in it, and it’s a child of the server script for a gun tool. Upon the player equipping the tool, it clones the gui to the tool holder’s PlayerGui, and sets the text to the ammo of the gun.

Only problem is, the text doesn’t ever update! It just stays as “Label” forever, but bizarrely, upon unequipping the gun tool the text updates for about a frame when destroying the clone of the ammo gui.

Additionally, I am also manually looking at the text of the cloned gui while in game, and the text of the gui instance is changed to the ammo correctly, but the gui on screen doesn’t display these changes!

My ammo is an IntValue that is a child of the same server script.

Here’s the code that clones the gui upon the player equipping the tool:

tool.Equipped:Connect(function()
	local ammoGui = script.AmmoGui:Clone()
	ammoGui.AmmoStatus.Text = ammo.Value.."/25"
	ammoGui.Parent = game.Players:GetPlayerFromCharacter(tool.Parent).PlayerGui
end)

And here’s the code that’s supposed to update the gui:

ammo:GetPropertyChangedSignal("Value"):Connect(function()
	if game.Players:GetPlayerFromCharacter(tool.Parent) then 
		game.Players:GetPlayerFromCharacter(tool.Parent).PlayerGui.AmmoGui.AmmoStatus.Text = ammo.Value.."/25"
	end
end)

And finally here, the on-screen gui text is just “Label” while in the properties of the gui its text is “25/25”
label
workspace
properties

Your problem is that you cannot update GUIs from the server, all of the updating needs to be done in a local script. It is correct to do the cloning of the GUI and ammo value on the server, but all GUI updating needs to be done in a local script.

1 Like

you can also use remote events to connect with local scripts as well

I see, I will look into this. I always get confused with client/server related things on the roblox engine!
Thank you

Swap these two lines, this way the parent will be set first and the event will work.