Display String Value On Text

Hello, I was wondering how do you display a string value on a text? The method im using is not working.

local timespentLable = script.Parent.TimeSpent.Visible

local function onTimeChanged(timeValue)
	timespentLable.Text = ""..tostring(timeValue)
end


local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local timeSpent = leaderstats.Parent:WaitForChild("Time")

onTimeChanged(timeSpent.Value)

timeSpent.Changed:Connect(function(timeValue)
	onColorChanged(timeValue)
end)

It give me this error Players.5Flipz.PlayerGui.Frames.Stats.Canvas.Displays:9: attempt to index boolean with 'Text'

Your timespentLable variable points to a property of your textlabel called Visible, which is a true or false (boolean) value dictating whether the respective textlabel is visible or not.

The quickest solution would be to just not index Visible when instantiating the variable:

local timespentLable = script.Parent.TimeSpent

Thus, you can now index property Text of the textlabel:

timespentLable.Text = timeValue --(functionally) equivalent to script.Parent.TimeSpent.Text = ...

However, be wary of portions of your code that used the timespentLable variable as a boolean, as they will stop functioning correctly. You can resolve those errors by finding them in runtime.

It is also important to note that you should be able to set the Text property directly to a number, and Roblox will essentially take care of its conversion to a string. You don’t need to precede timeValue with "" .. or wrap it in tostring().

Omg I am so embarrassed lol thank you