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

How to get a button click to add to a value in the button?

I have a button that is supposed to open after like 15 clicks. I put a value in the button thats set at 0 and I want the script to add 1 to the button each time it's clicked until it reaches 15 then does an action. I'm pretty new and terrible at scripting so this is what I have so far. How do i get it to actually do math if not open + 1?

open = script.Parent.Value

function onClicked()
	if open >= 15 then
		open += 1
	else
		for _,v in pairs (script.parent.parent.parent["Hall Light"]:GetChildren()) do
			if v:IsA("Part") then
				v.Anchored = false
			end
		end
	end
end

So i figured it out, this is my final code that got it to work

open = script.Parent.Open.Value

function onClicked()
    if open < 15 then
        open = open + 1
    elseif open >= 15 then
        for _,v in pairs (script.parent.parent.Parent.HLG:GetChildren()) do
            if v:IsA("Part") then
                v.Anchored = false
            end
        end
    end
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked) --dont touch

1 answer

just a few small mistakes

open = script.Parent.Value

function onClicked()
	if open < 15 then
		open = open + 1
	elseif open >= 15 then
		for _,v in pairs (script.parent.parent.parent["Hall Light"]:GetChildren()) do
			if v:IsA("Part") then
				v.Anchored = false
			end
		end
	end
end

3 comments

0

So it doesn't seem to be working. It isn't adding to the Value that I have inside the button.

0

are you using an int value?

0

Yes

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