Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 14 days 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 5 — 14d

3 answers

Log in to vote
0
Answered by 14 days ago
Edited 14 days 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 0 — 14d
0
pls accept my ans panvvan 5 — 14d
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 — 14d
Ad
Log in to vote
0
Answered by 14 days ago
Edited 14 days 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 14 days 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