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

How do I make a value go up on touch script?

So I'm working on a Bank robbery heist mission and I put a value of how many ATMs have been robbed. When the player touches/robs the ATM, I want the value to go up. I don't know how to make it go up. Here is the code.

function onTouch()
	script.Parent.Parent.Value.Value = -- ? 
end
script.parent.Touched:connect(onTouch)

1 comment

0

btw is it a bool value string or int?

3 answers

✓ Accepted answer
script.parent.Touched:connect(function(hit)
	script.Parent.Parent.Value.Value = script.Parent.Parent.Value.Value + 1
	wait(0.5)
end)

3 comments

0

thank you

0

pls accept my ans

0

While this is correct, consider adding a debounce (even if a small one) so there aren't hundreds of increments every second when someone abuses your ATM with shiftlock rotations.

function onTouch()
    script.Parent.Parent.Value.Value =   script.Parent.Parent.Value.Value + 1--Change 1 to anything you want
end
script.parent.Touched:connect(onTouch)

Including a debounce (if you want):


local Debounce = false

script.Parent.Touched:Connect(function()
	if Debounce == true then return end
	Debounce = true

	script.Parent.Parent.Value.Value = script.Parent.Parent.Value.Value + 1
	wait(0.5)

	Debounce = false
end)

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