Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

These buttons to increase a value by one and reduce a value by one do not work?

I do not receive any errors while attempting to run this function, but the values do not increase.

-- In a LocalScript in StarterGui:
 
-- Create ScreenGui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

-- Create RedValue
local redValue = 0

-- Create RedInput
local redInput = Instance.new("TextLabel")
redInput.Name = "Red"
redInput.Parent = screenGui
redInput.Position = UDim2.new(0.5,-100,0.5,-75)
redInput.Size = UDim2.new(0,200,0,50)
redInput.BackgroundColor3 = Color3.new(255,0,0)
redInput.Text = ("Red Value = " .. redValue)

-- Create RedInputLeftArrow
local redLess = Instance.new("TextButton")
redLess.Name = "Red Reduce by One"
redLess.Parent = screenGui
redLess.Position = UDim2.new(0.5, -150, 0.5, -75)
redLess.Size = UDim2.new(0, 50, 0, 50)
redLess.BackgroundColor3 = BrickColor.White().Color
redLess.Text = "<"
 
-- Bind function to button click
redLess.MouseButton1Down:connect(function()
	if redValue == 0 then
		
	elseif redValue >0 and redValue <=255 then
		redValue = redValue-1
	end
end)

-- Create RedInputRightArrow
local redMore = Instance.new("TextButton")
redMore.Name = "Red Increase by One"
redMore.Parent = screenGui
redMore.Position = UDim2.new(0.5, 100, 0.5, -75)
redMore.Size = UDim2.new(0, 50, 0, 50)
redMore.BackgroundColor3 = BrickColor.White().Color
redMore.Text = ">"
 
-- Bind function to button click
redMore.MouseButton1Down:connect(function()
	if redValue == 255 then
		
	elseif redValue <255 and redValue >=0 then
		redValue = redValue+1
	end
end)

I can guess the values probably need to be local, if that is the solution, please answer and I will upvote you.

1 comment

1

Add prints

1 answer

From doing stuff like that my self I believe you need to make "redMore" local just like "local redMore"

local redMore.Name = (Name)

Num 2 idea:

The value at the top isn't defined as an actual value of anything, I don't think it can increase as a string, I'd suggest you Instance.new a value and make that value "redValue" instead so you are actually increasing a number/value of something.

1 comment

0

redValue has been defined as 0 at the top, and with the redMore and redLess Click functions (listed below their options) I try to increase the value, or decrease it.

This discussion is preserved as it was. New answers, comments, and votes are closed.