[Solved] Help displaying an IntValue on a TextLabel

I’m creating a counter for the amount of clicks of a TextButton GUI. The amount of clicks is supposed to be displayed on a TextLabel on a part in the Workspace. Currently, I have an IntValue inside of the part that increases upon every click of the TextButton.

Despite all this, I can’t find out how to display the Value of the IntValue as the text on the TextLabel.

Here is the current script I am using:

image

It may also be important to note that no errors are displayed in the output.

Hope someone can help!

1 Like

convert the intValue into string by using tostring()

1 Like

Like this?

image

yes
(characters limitssssssss)

I’m afraid it didn’t work. Still nothing in the output in terms of errors.

also you might have to do script.Parent.TextLabel.Text = tostring(Value.Value) if it doesnt change the text

Adding onto this, your script won’t work as expected as according to your Value variable, you have TextLabel.Text = script.Parent.Value.Value, and you’re using .Changed incorrectly. Try the following instead.

local TheValue = script.Parent.Value
local TextLabel = script.Parent.TextLabel

TheValue:GetPropertyChangedSignal("Value"):Connect(function()
   TextLabel.Text = tostring(TheValue.Value)
end)

Edit: Nevermind about the first part, turns out you’re trying to get the value property of something named value. I was under the assumption it was a direct path to an IntValues value.

This didn’t seem to work either.

Actually, a more likely theory here is getting more information about the type of scripts these are.

You say that the IntValue is increased using the following script. I assume you have a MouseButton1Click on a TextButton in a LocalScript which increases the value. Are you changing the value directly from that LocalScript, or are you changing it on the server with a RemoteEvent? If possible, could you provide us the code which you are using to increase the IntValue?

Yes, the IntValue is being increased directly from a LocalScript inside the TextButton.

script.Parent.MouseButton1Down:Connect(function()

Value.Value = Value.Value + 1

end)

Is the script you’re listening to changed in a Server Script or LocalScript?

If it’s a ServerScript:
Because you’re changing the value on the client, it won’t actually see the changes on the server side. According to the script, the changed event isn’t firing because it does not see any changes. To fix this, do the following:

--client 
-- this requires a remoteEvent in ReplicatedStorage
script.Parent.MouseButton1Down:Connect(function()
   game.ReplicatedStorage.RemoteEvent:FireServer()
end)
--server

local value = RefrenceToWhereTheValueIs
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
   value.Value += 1 
end)

-- at this point it may be easier to simply change the textLabel whenever the RemoteEvent is fired, but this should fix it

If it’s a LocalScript:
Try converting it to a ServerScript and then following the steps above!

2 Likes

This works! Thanks a bunch for all your help!

1 Like

Converting a number to a string won’t do anything but use just a tiny bit more resources. The compiler already converts the number into a string so no conversion is needed (when can we get this for booleans).

1 Like