Hello! So I have been having some troubles, with my game.
What do you want to achieve? I want a value to be set as a text label.
What is the issue? The Textlabel isn’t being set to anything, even tho the value is way bigger than 0.
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)
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
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.
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.
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
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")