! | Making an IntValue Equal to a TextLabel

Goal:
Each player’s hunger value will show on their screen. (Like this, but it updates whenever the IntValue changes and everyone gets their own)
image

my script:

I’m not sure on how to make the IntValue equal to the TextLabel. Since each player has their own one which they get when the game starts, I do not know how to reference it.

Here is what I tried, though. I would love it if someone showed me a better method! :smiley:

game.Players.PlayerAdded:Connect(function(plr)

	local playerWellness = Instance.new("Folder")
	playerWellness.Name = "Wellness"
	playerWellness.Parent = plr

	local hunger = Instance.new("IntValue")
	hunger.Name = "Hunger"
	hunger.Parent = playerWellness
	hunger.Value = 100

	local GuiText = hunger.Value
	GuiText.Changed:Connect(function()
		local hungerValue = game.StarterGui.ScreenGui.Hunger.hungerValue
		hungerValue.Text = hunger.Value 
	end)
end)

Information:

  • Everything else works, the value updates appropriately
  • there are no errors in the output
  • if you are wondering the point of playerwellness, there’s a purpose for that (i followed a tutorial)

replace startergui with PlayerGui

1 Like

you’re changing StarterGui which means the ui will replicate to all the players,
this will fix it.
local hungerValue = Player.PlayerGui.ScreenGui.Hunger.hungerValue

1 Like

ohh, okay thank you! will i need to create a new instance where i make a player gui? I can’t find where I make one, do you know how? :smiley:

its better to interact with the guis locally
you can make a localscript
and put it inside the textlabel

local Player = game.Players.LocalPlayer
local HungerValue = Player:WaitForChild("Wellness").Hunger
HungerValue.Changed:Connect(function(val)
script.Parent.Text = val
end)
2 Likes