Making a GUI text set to locally show a player's internal value

I built some scripts where the player gets a child value and they’re supposed to find out what that number is and then send the value in a chat message to get rewarded.
The number is different for all players, so the answer can’t just be handled from one player to all players.
Until that point it’s all fine, but the GUI that tells the players the answer isn’t working, it’s supposed to show you your own value.
I’m gonna send the value script too just in case it’s needed for reference.
Thanks in advance!
Server Script - Makes the value inside the player

game.Players.PlayerAdded:connect(function(p)

local tnumber = Instance.new("IntValue")

tnumber.Name = "tnumber" 

tnumber.Value = math.random(100000,999999) 

tnumber.Parent = p

end)

Local Script - Is supposed to set the GUI text to the player’s internal value

local players = game:GetService("Players")

local IntValue = players.LocalPlayer.tnumber

while true do

players.LocalPlayer.PlayerGui.TNumberPaper.ImageLabel.TextLabel.Text = tostring(IntValue.Value)

end

i think you have to use string value
Edited: wait nvm

I tested it, and it worked.

Notes:

1-When you’re While Looping, don’t forget to add a delay[here, use task.wait().
2-Instead of accessing into the UI from the Player, why not just access it from where the UI is located?

--Server
game.Players.PlayerAdded:connect(function(p)
	local tnumber = Instance.new("IntValue")
	tnumber.Name = "tnumber" 
	tnumber.Value = math.random(100000,999999) 
	tnumber.Parent = p
end)

--Client
local players = game:GetService("Players")
local IntValue = players.LocalPlayer:WaitForChild("tnumber")

while true do
	script.Parent.Text = tostring(IntValue.Value)
	task.wait()
end

image

1 Like