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

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

Asked by 4 years ago

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)
0
btw is it a bool value string or int? panvvan 20 — 4y

3 answers

Log in to vote
0
Answered by
panvvan 20
4 years ago
Edited 4 years ago
script.parent.Touched:connect(function(hit)
    script.Parent.Parent.Value.Value = script.Parent.Parent.Value.Value + 1
    wait(0.5)
end)
0
thank you MrMonthh 11 — 4y
0
pls accept my ans panvvan 20 — 4y
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. Sparks 534 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
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)
Log in to vote
0
Answered by
Zeuxulaz 148
4 years ago

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)

Answer this question