Local script wont update SurfaceGUI Text

Hello developers,

So im having an issue right now reguarding a Surface GUI text not updating. The script that i am using is a local script since the point of it is to show the players PERSONAL stats. If anyone could help, it would be appreciated. Also, if its not possible to change text through a local script, is there any way i can make it so it is local and only shows local player stats?

local player = game.Players.LocalPlayer

local stat = player.PlayersStats.RoundsPlayed.Value

while wait() do

script.Parent.SIGN.Text = stat

end
1 Like

You can do this on a local script, but it’ll only show for that client.
Instead of doing an infinite loop, try this:

local player = game.Players.LocalPlayer
local stat = player.PlayersStats.RoundsPlayed
stat.Changed:Connect(function(value)
    script.Parent.SIGN.Text = value
end)

This function will only fire if the stat is changed from the server or that player’s client, not from any other client.

2 Likes

Hey, so i tried it and it still doesnt update the text. Does it need to be ran from a script? And the players stats does get updated from a script.

It should be ran from a local script. However, I just realized you were talking about a surfaceGUI and not a screenGUI. Stated from the API reference for local scripts, a LocalScript will only run Lua code if it is a descendant of one of the following objects:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service

It looks like the local script is a child of the surfaceGUI probably located in the workspace.

1 Like

Oh thanks for letting me know. Would there be any way of making the surfaceGUI text update?

Try moving the local script from the surfaceGUI to StarterPlayerScripts. Using the function I provided, change the script.Parent.SIGN.Text = value to workspace...SIGN.Text = value This exact code wont work because I don’t know where the surfaceGUI is, but you get it.

3 Likes

Thank you for the help! I really appreciate it.

2 Likes