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

How to make a variable +1 when a brick is touched?

Asked by
pevdn 32
3 years ago

Sorry if this is really easy, but how do I make a variable get one more number in its value when it is touched? For example - triesUsed = 0 touches brick triesUsed = 1

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I create this simple script:

Tries = 0 --The Value

script.Parent.Touched:Connect(function() --Detect If It Touched 
    Tries = Tries + 1 --Adding A Number To The Value
    wait()
    print(Tries) --Print The Value
end)    

Hope It Helps!

0
Thanks so much! pevdn 32 — 3y
0
Np :D The_Saver31 260 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

You could also use a NumberValue to make it able to be detected in multiple scripts.

Example:

local Value = Instance.new("NumberValue", script.Parent) -- script.Parent is the script's parent
Value.Value = 0

wait = false -- Cooldown

script.Parent.Touched:Connect(function()
    if wait == false then -- If the cooldown isn't active.
        wait = true -- Cooldown Active
        Value.Value = Value.Value + 1
        wait(5) -- Change the 5 to how many seconds the cooldown you want to be.
        wait = false -- Stop the cooldown
    end
end)

Hope this helped!

Answer this question