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

Wait before growing?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago
--When I walk on this part, it keeps growing from my legs touching it.
--How would I make a wait before it grows again?
x = script.Parent

x.Touched:connect(function()

    x.Size = x.Size + Vector3.new(1,1,1)
    x.CFrame = CFrame.new(-8,-1,-3)
end)
0
You would need to use a Debounce; A Debounce is a thing-a-bob Variable that prevents a Function from firing multiple times on execution of the code (or chunk). WIKI Documentary on Debounce: http://wiki.roblox.com/index.php?title=Debounce TheeDeathCaster 2368 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago
x = script.Parent
settime= 1
mov = false

x.Touched:connect(function()
if mov == false then
mov=true
x.Size = x.Size + Vector3.new(1,1,1)
x.CFrame = CFrame.new(-8,-1,-3)
wait(settime)
mov=false
end
end)
0
Watch this: https://gyazo.com/fb1d8b4a96a720c5d25bc145974934a6 I want when I touch it it grows 1,1,1+ then wait 1 second and if you touch it, it grows another 1,1,1+ FiredDusk 1466 — 8y
Ad
Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
8 years ago

As Alpha stated, you'd simply need to add in a debounce. To do this, you just need to add in a variable, which we can call "debounce" for simplicity. We'll set it up like this:

local x = script.Parent
local debounce = false

x.Touched:connect(function()
    if not debounce then --Checks if it's true
        debounce=true --Makes it so that it wont work until turned off.
        x.Size = x.Size + Vector3.new(1,1,1)
        x.CFrame = CFrame.new(-8,-1,-3)
        wait(1) --Waits before re-enabling it
        debounce=false --Sets it back to false so script can work
    end
end)

Ok, so now your script should work fine. If you have any further problems/questions, please leave a comment below. Hope I helped :P

-Dyler3

Answer this question