IntValue.Value + 1

I’m trying to make it so it adds +1 to a value, and displays the value at the very end (Like a quiz result.)
Can anyone help? This is my current code

-- clicking a correct answer
script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Value.Value = script.Parent.Parent.Parent.Value.Value + 1
end)

And

-- for the result at the end
local value = script.Parent.Parent.Parent.Value
while true do
	script.Parent.Parent.POINTS.Text = value
	wait(1)
end

Could anyone please tell me what I’m doing wrong?

1 Like

‘’
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Parent.Value.Value = script.Parent.Parent.Parent.Value.Value + 1
end)‘’
instead of doing this, you can js dk ‘‘script.Parent.Parent.Parent.Value.Value += 1’’
this is more clean.
What does the error message say?

Uh, there is no error message.

I’m trying to figure out how to add onto intvalue, since it just shows 0.

ok, is it working after you changed it? on the first script, try printing its value, to see if it works.

my eyes

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

(also what kind of quiz system are you making that uses script.Parent.Parent instead of just referencing it like yourmodelhere.intvalue)

It does show 1, but at the end it still just says 0

It still says 0 like in a UI or something? It is a bit confusing since you said it shows 1 but also says 0

Sorry I wasn’t specific, yes in a UI.
image
The “inf” is where the points should be showing but it just shows the value 0

And… is there a script that gets the intvalue and changes the UI? I think that might be your problem

1 Like

yes hes right, your code isnt super clean, but thats ok, you will probably have to use ToString, as the text in a textlabel doesn’t support regular numbers, I think.

1 Like

ye thats the second script, i think.

heres your improved (and probably working code)

-- for the result at the end
local value = script.Parent.Parent.Parent.Value
value.Changed:Connect(function()
    script.Parent.Parent.POINTS.Text = tostring(value)
end)

This needs to be Value.Value to get the actual value of the value instance.

So

TextLabel.Text = value.Value

yes, hes right by using tostring, as like i mentioned, textlabels dont support regular numbers.

no it doesn’t, as the var says .Value already
as in it says ‘‘local value = blahblah.Value.Value’’

I tried it and it just displayed the placeholder word, “inf”

1 Like

sorry wait i made a mistake

-- for the result at the end
local value = script.Parent.Parent.Parent
value.Changed:Connect(function()
    script.Parent.Parent.POINTS.Text = tostring(value.Value)
end)

your previous method was storing the value… which would be 0

This is the reference to the actual value. 3 parents and one value is what he put for the text.

local value = script.Parent.Parent.Parent.Value

This will not work as he’s just getting the actual ValueInstance instead of the value itself.

1 Like

Don’t want to be rude, but you forgot a value at the variable