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

How do I make a number that rises when a button is pressed, but stops when toggled again??

What I have so far: workspace.Temp.Current.Value=(0+1) wait(1.5)

script.Parent.MouseClick:connect(OnClicked) I need this because I am working on a core, but I need a certain temperature for the cord to blow up. But I don't want it to go down when it is toggled off.

Here is another script, I want the number to go down:

workspace.Temp.Current.Value=(0-1) wait(3.5) Nothing is working out for me so could someone please help me? ):

5 comments

1

what kind of button? key? GUI? mouse?

0

It's a click detector

0

Why use math? It's basic math. 0+1 is 1, so just put 1. 0-1 is -1, so just put -1

0

Format your code properly

0

local button = (Part To Click)

2 answers

For this, you should make a BoolValue object so you can toggle it's Value Property.

Once a BoolValue is setup, you can use the Changed event to add points when its true. You can put this in ServerScriptStorage.

local toggleVal = game.ServerStorage.BoolValue --Your BoolValue
local lastVal = false --The previous state of the BoolValue
local Val = workspace.Temp.Current --The value to increase

toggleVal.Changed:Connect(function(change) --Changed event
	if change ~= lastVal then --If the change is different from the lastval
		lastVal = change;
		while lastVal and wait(1) do --While it is toggled
			val.Value = val.Value + 1; --Increase the value
		end
	end
end)

Now, have a Script inside the Button that uses the MouseClick function on a ClickDetector object. Make this toggle the BoolValue.

local toggleVal = game.ServerStorage.BoolValue --Your BoolValue

script.Parent.MouseClick:Connect(function() --MouseClick event
	toggleVal.Value = not toggleVal.Value --Toggle the value
end)

1 comment

1

I interpreted his problem to mean that, while the button was "activated", continuously increment the value. Stop incrementing if the button is pressed again. Could be wrong, though.

Maybe make a boolvalue and do ifelse to check if it was pressed like

funtion OnClicked () if OnOrOff == false then --On Or Off means the BoolValue --What you Want OnOrOff = ture elseif OnOrOff == true then --TheToogle OnOrOff = false end

script.Parent.MouseClick:connect(OnClicked)

2 comments

0

Sorry for my answer just signed up for the site!

1

Format your code mate

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