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

How can I make a number value increase by clicking on a ImageButton?

Hey Guys! So, a friend and I are working on a script. The whole purpose of the script is for a number value increase just by clicking on an ImageButton. What we tried was we using "MouseButton1Cick", if you can help us or give us any advice please do. We're working on a project and the purpose is for it to change everytime you click an arrow to the right.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local number = script.Parent.Parent.Number

local humanoid = char:WaitForChild('Humanoid')
local torso = char:WaitForChild('Torso')
local torsogui = torso:WaitForChild('Number')
local guitext = torsogui:WaitForChild('TextLabel')
local debounce = true

function Increase()
	if number.Value < 0 then
		number.Value = number.Value + 1
	end
	number.Value = number.Value + 1
end

script.Parent.MouseButton1Click(function()
	if debounce then
		debounce = false
		Increase()
	wait(1)
	debounce = true
	end
end)

Here is a screenshot so you can understand. StarterGui - https://prnt.sc/fu2x93 Script - https://prnt.sc/fu2xi9

2 comments

0

Any errors?

0

Yes, everytime we click On the Image label, the number value does not increase.

1 answer

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local number = script.Parent.Parent.Number.Number --You're using TextLabel, So I added the children of the TextLabel , which is the IntValue or Number

local humanoid = char:WaitForChild('Humanoid')
local torso = char:WaitForChild('Torso')
local torsogui = torso:WaitForChild('Number')
local guitext = torsogui:WaitForChild('TextLabel')
local debounce = true

function Increase()
    if number.Value < 0 then
        number.Value = number.Value + 1
    end
    number.Value = number.Value + 1
end

script.Parent.MouseButton1Click(function()
    if debounce then
        debounce = false
        Increase()
    wait(1)
    debounce = true
    end
end)


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