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

How to set value from leaderstats in the text GUI?

Google translate, sorry

First, I created a new Script in ServerScriptService and wrote in this code:

game.Players.PlayerAdded:connect(function(player)
     local leaderstats = Instance.new("Model")
     leaderstats.Name = "leaderstats"
     leaderstats.Parent = game.Players.LocalPlayer

     local brown = Instance.new("IntValue")
     brown.Name = "Brown"
     brown.Value = 0 
	 brown.Parent = leaderstats

 end)

Further, in a Workspace created LocalScript and wrote this code:

local player = game.Players.LocalPlayer
local brown = game.StarterGui.GameUserInterface.HudGui.MainFrame.PlayerStats:WaitForChild("BrownMaterial")
while true do
	brown.Text = player:WaitForChild("leaderstats"):WaitForChild("Brown").Value
end

Everything works fine, except for the writing values from "Brown" (leaderstats) in my GUI(BrownMaterial is TextLabel)

1 answer

✓ Accepted answer

Once the client spawns in, everything from StarterGui is cloned into their PlayerGui. This is where you need to reference the 'brown' object from.. here is a better explanation for this.

Some additional things you need to know are:

  • 1) Using a while loop with no yield in it will crash your client. Add a wait

  • 2) The Changed event is much more efficient when trying to auto-update something correlating to a specific value.

local player = game.Players.LocalPlayer
local val = player:WaitForChild("leaderstats"):WaitForChild("Brown");
local ui = player.PlayerGui.GameUserInterface.HudGui.MainFrame.PlayerStats;
local brown = ui:WaitForChild("BrownMaterial")

val.Changed:Connect(function(change)
	brown.Text = change;
end)

1 comment

0

Thank you for your response, but I did not solve my problem :c .I changed my LocalScript to yours, but nothing changed. In the output there are no errors. I think the problem is that the LocalScript can not change the TextLabel with the value of leaderstats. How to solve it?

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