Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a better way to do this? Updating Stats with Text

I was wondering if there was a better way to do this. I was looking at the GetPropertyChangedSignal and IntValue.Changed.

local plr = game.Players.LocalPlayer -- self explanatory
local statss = game.ReplicatedStorage:FindFirstChild("Stats") -- finding the folder holding stats
local folder = script.Parent.Main.values -- opening the folder containing the text inside the gui

function update()
	wait(1)
	local stats = statss:FindFirstChild(plr.Name) -- finding the players stat folder with their username

	for i,v in pairs (folder:GetChildren()) do
		v.Text = v.Name..": ".. tostring(stats:WaitForChild(v.Name).Value) -- grabbing the stats and text inside gui and changing it

	end
end
while wait(1) do -- this is the main part I was wondering about
	update()

end

If there is an entirely better way to do this, let me know please. Still learning.

1 answer

If the number of values you have doesn't change, you can attach a .Changed to each of them, and update the gui text correspondingly, I can't give you an example since I don't know their names but you'd just do this, and paste the changed code for each value.

local plr = game.Players.LocalPlayer
local plrStats = game.ReplicatedStorage:WaitForChild("Stats"):FindFirstChild(plr.Name)
local plrGuis = script.Parent.Main.values

plrStats.Cash.Changed:Connect(function(n)
	plrGuis.Cash.Text = "Cash: "..n
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.