Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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? ):

1
what kind of button? key? GUI? mouse? creeperhunter76 554 — 7y
0
It's a click detector saSlol2436 716 — 7y
0
Why use math? It's basic math. 0+1 is 1, so just put 1. 0-1 is -1, so just put -1 hiimgoodpack 2009 — 7y
0
Format your code properly Goulstem 8144 — 7y
0
local button = (Part To Click) lego_spinjitsu -5 — 7y

2 answers

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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
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. nicemike40 486 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago

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)

0
Sorry for my answer just signed up for the site! NerdBow_Gaming 41 — 7y
1
Format your code mate Goulstem 8144 — 7y

Answer this question