I’m trying to make a UI with some buttons that will increase and decrease a value like this:

The arrows would make it increase or decrease by a value of 1.
However, the script I made isn’t working. I get no error messages and the value fails to increase or decrease on my UI when I launch the game and click the buttons.
Here is the code:
local segmentCount = game.ReplicatedStorage:WaitForChild("segmentValue")
local segmentCountDisplay = script.Parent.Segment_Number.Text
local increaseSegment = script.Parent.Increase_Segements
local decreaseSegment = script.Parent.Decrease_Segments
function updateText()
segmentCountDisplay = segmentCount.Value
end
updateText()
segmentCount:GetPropertyChangedSignal("Value"):Connect(updateText())
increaseSegment.MouseButton1Click:Connect(function()
segmentCount = segmentCount + 1
end)
decreaseSegment.MouseButton1Click:Connect(function()
segmentCount.Value = segmentCount - 1
end)
And here is the arrangement I have it in my explorer tab:

I also need this value to be called upon because I need to use the value in a different script. If I’m going about this script the wrong way, please let me know.
If anyone is able to help me resolve this issue it would be greatly appreciated. Thanks!
1 Like
If SegmentCount is an IntValue, try doing SegmentCount.Value = segmentcount+1 or -1
Just tried it like this:
increaseSegment.MouseButton1Click:Connect(function()
segmentCount.Value = segmentCount + 1
end)
decreaseSegment.MouseButton1Click:Connect(function()
segmentCount.Value = segmentCount - 1
end)
and like this:
increaseSegment.MouseButton1Click:Connect(function()
segmentCount.Value = segmentCount.Value + 1
end)
decreaseSegment.MouseButton1Click:Connect(function()
segmentCount.Value = segmentCount.Value - 1
end)
And nothing seems to work still. 
1 Like
Try calling UpdateText() on mousebutton1click
local buttonIncrease = script.Parent.Incease
local buttonDecrease = script.Parent.Decrease
local num = 0
buttonIncrease.MouseButton1Click:Connect(function()
num += 1
script.Parent.Segment_Number.Text = num
end)
buttonDecrease.MouseButton1Click:Connect(function()
num -= 1
script.Parent.Segment_Number.Text = num
end)
That should work better, what you have it too complex for it’s function.
3 Likes
You should also never use a = a + 1 , rather use a += 1 or -= 1
1 Like
local segmentCountDisplay = script.Parent.Segment_Number.Text
local increaseSegment = script.Parent.Increase_Segements
local decreaseSegment = script.Parent.Decrease_Segments
function updateText()
segmentCountDisplay = segmentCount.Value
end
increaseSegment.MouseButton1Click:Connect(function()
segmentCount.Value += 1
updateText()
end)
decreaseSegment.MouseButton1Click:Connect(function()
segmentCount.Value -= 1
updateText()
end)
You’ll need a .Changed event. Every time the value changes, it’ll change the text to the value.
segmentCount.Changed:Connect(function()
segmentCountDisplay.Text = segmentCount.Value
end)
Just what I needed. Thank you! I didn’t know about the += and -= until now, so thanks. 
1 Like
You should ALSO not ever use something like this:
local segmentCountDisplay = script.Parent.Segment_Number.Text
I made this example. Excuse the bad UI, I made it in 2 minutes. The code, and output:
local text = script.Parent.Parent.TextBox.Text
script.Parent.MouseButton1Click:Connect(function()
print (text)
script.Parent.Parent.Frame.TextLabel.Text = text
script.Parent.Parent.Frame.TextLabel.MaxVisibleGraphemes = 0
for i = 1, 250 do
script.Parent.Parent.Frame.TextLabel.MaxVisibleGraphemes += 1
wait(0.2)
end
end)
1 Like