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

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

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

✓ Accepted answer

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!

2 comments

0

Thanks so much!

0

Np :D

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!

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