I can't consistently reflect a value to text

  1. What do you want to achieve?
    I have a LocalScript (its in startergui/playergui) to recognize a value(its in player too). However, i also want to continuously update this value in a text within the PlayerGUI. But currently, it only stays with the initial form when i start the server and does not update the text when the value changes
local player = game.Players.LocalPlayer

local Datas = player.Datas
local Points = player.Datas.Points

--CODE--
local PointsText = player.PlayerGui.PointsShowGui.PointsShow

local function updateText()
	PointsText.Text = "POINTS: "..Points.Value
end

updateText()

Points.Changed:Connect(updateText())

photo1
photo2

How can i solve it to that when value changes my text everytime changes too

Points.Changed:Connect(updateText) -- omit the (parentheses)

1 Like

I think you should use tostring()
it will look like that:

PointsText.Text = "POINTS: "..tostring(Points.Value)

and if Points is a Int or Number value then you can use

Points:GetPropertyChangedSignal("Value"):Connect(updateText)

to fire function only when Value changed.

1 Like

The problem is most likely that you are changing the value on a local script. For the server to be able to read the new information, the value has to be changed on a server script. Try using remote events if you need.

1 Like

You need to put the script inside the Label


local player = game.Players.LocalPlayer

local Data = player.Data
local Points = Data:WaitForChild("Points")

local PoinsText = script.Parent -- Put the script in the Label

PointsText.Text = "POINTS: "..Points.Value

Points:GetPropertyChangedSignal("Value"):Connect(function()
PointsText.Text = "POINTS: "..Points.Value
end)

Pretty simple script hope I helped! :slight_smile:

1 Like

The Changed event for all objects that inherit ValueBase are different. Changed will only fire on these objects if their value is changed, not if any property is changed.

1 Like

Oh its really simple i dont understand how i didnt think about it really thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.