Having Trouble With Textlabels

Hello! So I have been having some troubles, with my game.

  1. What do you want to achieve? I want a value to be set as a text label.

  2. What is the issue? The Textlabel isn’t being set to anything, even tho the value is way bigger than 0.

  3. What solutions have you tried so far? I have tried re wording it and it won’t work.

The Values (Meat and Money) are firstly created and parented to the player when they first join the game. There is nothing in the output/dev log thing that is saying there is anything wrong with it. (I wait 10 seconds just incase it doesn’t load properly.)

(This code is in a local script, and it has some other Gui releted stuff.

local Meat = game.Players.LocalPlayer:FindFirstChild("Meat")
local Money = game.Players.LocalPlayer:FindFirstChild("Money")

local MeatDisplay = script.Parent.MeatCounter.MeatDisplay
local MoneyDisplay = script.Parent.MoneyCounter.MoneyDisplay


game.Players.PlayerAdded:Connect(function(player)
	wait(5)
	local inGame = true

	while inGame == true do
		MeatDisplay.Text = "Meat.Value"
		MoneyDisplay.Text = Money.Value
	end
	
end)

Greetings! :wave:

I believe the PlayerAdded event was unnecessary, you’ve also seemed to leave quotation marks on Meat.Value making it display that exact text, and instead of creating a variable to loop something you can simply do:
while true do end´

Try this:

local Meat = game.Players.LocalPlayer:WaitForChild("Meat")
local Money = game.Players.LocalPlayer:WaitForChild("Money")

local MeatDisplay = script.Parent.MeatCounter.MeatDisplay
local MoneyDisplay = script.Parent.MoneyCounter.MoneyDisplay

while wait() do
	MeatDisplay.Text = Meat.Value
	MoneyDisplay.Text = Money.Value
end

Hope this helps! :smile:

Your method works but to make some improvement you don’t need to use

while true do ` end

using this method it might slow down or crash his game as the while loop will run all the time, instead I recommend using the IntValue.Changed event (IntValue | Documentation - Roblox Creator Hub) it will only run when the meat/money value is changed so it will only change the value when necessary.

I tried it, and it still won’t update the textlabel. Even tho the meat/money values are 1000 Could it be a Roblox Engine Related Bug?

does it drop any error

30charrrr

Nope! Nothing relating to it. I not sure what is happening

try replacing with MeatDisplay.Text = tostring(Meat.Value)

Nope! The Textlabel isn’t updating. Even tho the value is 1000

If you put a print after the WaitForChilds, does it print?

Are you sure it’s inside the player? And not in a folder called “leaderstats”?
If so then define the folder leaderstats before you define the money or meat.

Yes I am sure it is inside the player. I had the same script but it had FindFirstChild: And it still won’t load.

I changed it to this. After some feedback.

local Meat = game.Players.LocalPlayer:WaitForChild("Meat")
local Money = game.Players.LocalPlayer:WaitForChild("Money")

local MeatDisplay = script.Parent.MeatCounter.MeatDisplay
local MoneyDisplay = script.Parent.MoneyCounter.MoneyDisplay

while wait() do
	MeatDisplay.Text = tostring(Meat.Value)
	MoneyDisplay.Text = Money.Value
end 

does it work now and I’m pretty sure that is the problem is that your not working tostring.

Can I see the leaderstats script or where you made the Meat and Money values, and is the leaderstats script in a server script?

I recommend you instead of using a for loop you should use a GetPropertyChagedSignal function so it lags your game less.

edit: I notice someone already said this

I don’t use leasderstats.

game.Players.PlayerAdded:Connect(function(player)
		local Currencies = Instance.new("Folder")
	Currencies.Name = "Currencies"
	Currencies.Parent = player
	
	local meat = Instance.new("IntValue")
	meat.Name = "Meat"
	meat.Value = 1000
	meat.Parent = Currencies
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = 1000
	money.Parent = Currencies

end)

In your script you didn’t refernce it to the currencies folder for the text

1 Like

So the issue is you have parented all the currencies to a folder called “Currencies” so you’ll have to find that first before finding the actual instances like Meat and Money;

local folder = game.Players.LocalPlayer.Currencies

local Money = folder:WaitForChild("Money")
local Meat = folder:WaitForChild("Meat")
1 Like

Wow. Dang I am a major Derp. LOL sorry

1 Like

No problem that’s what we’re here for :+1:

1 Like