intValue won't change on button click

I have a simple script, that is supposed to change the value of a intValue on the mousebutton1click, but it won’t.

Additionally, how do I convert it to a string so I can make the int value appear as the text of a TextButton?

code:

local parent = script.Parent

parent.MouseButton1Click:Connect(function()
	script.Parent.Value = script.Parent.Value+1
end)
1 Like

first of all, you’re not changing anything,

Second you need to define your value like this:

local Value = game.ValueLocationHere.Value

if you’re doing script.Parent you’re getting the button, not the value.

here is an example you can use

local Value = game.ValueLocationHere.Value
local Parent = script.Parent

Parent.MouseButton1Click:Connect(function()
   Value = Value + 1
end)

Lastly, just change the IntValue and replace it with a StringValue.

This is client-sided code; the preferred way to call instances is through relative hierarchy (script.Parent).

Also, you can use tonumber() to convert a string into a number and tostring() to convert a number into a string.

I tried this (I changed the location to where the value was) and it didn’t give me a message in outbox. I’m super confused right now. I tried looking at its properties after clicking, but nothing happened, it stayed at zero (the default, which I haven’t changed)

What is the script.Parent referring to?
Can you provide a picture of the explorer?

using the tostring() function.

One thing that might be happening is you are not referring to the property value of the Instance IntValue but rather the Instance itself and trying to increment it by 1 which is most likely in this case.

This code won’t work. Change it to:

local IntValue = game.ValueLocationHere
local Parent = script.Parent

Parent.MouseButton1Click:Connect(function()
   IntValue.Value += 1
end)

“Value” will be a number such as 15 or whatever was set in the intvalue.

Will make the variable “Value” 16 (or whatever) not changing the IntValue.

1 Like

Full script:

local IntValue = game.StarterGui.ScreenGui.TextButton.intValue -- Change to your location
local Parent = script.Parent

Parent.MouseButton1Click:Connect(function()
	IntValue.Value += 1
	tostring(IntValue.Value)
	script.Parent.Text = IntValue.Value
end)