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

First when the script is fully done, you can touch again?

Asked by
iNicklas 215 Moderation Voter
9 years ago

First when its been on transparency = 1 you can touch again.

local p = script.Parent
local t = "5"

function Ontouch()
    p.Transparency = 0.1
    wait(t)
    p.Transparency = 0.2
    wait(t)
    p.Transparency = 0.3
    wait(t)
    p.Transparency = 0.4
    wait(t)
    p.Transparency = 0.5
    wait(t)
    p.Transparency = 0.6
    wait(t)
    p.Transparency = 0.7
    wait(t)
    p.Transparency = 0.8
    wait(t)
    p.Transparency = 0.9
    wait(t)
    p.Transparency = 1

end

p.Touched:connect(Ontouch)

2 answers

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

What you want to add is called a 'debounce':

local p = script.Parent
local t =  5 --You can't wait "5". :P

local deb = false --Our debounce variable

function Ontouch()

    if deb then return end --Don't do anything if debounce is on!
    deb = true --Turn it on otherwise...

    for i = .1, .9, .1 do --To avoid repetition
        p.Transparency = i
        wait(t)
    end
    p.Transparency = 1

    deb = false --Now that we're done, turn debounce off!

end

p.Touched:connect(Ontouch)
0
So if debounce = true, you have to wait for it to be false until you can touch it again? iNicklas 215 — 9y
0
Yes, because of line 8. adark 5487 — 9y
Ad
Log in to vote
0
Answered by
Scriptree 125
9 years ago
local p = script.Parent
local t = 5
local defaultTrans = 0 -- plug in the number you want the block's transparency to revert to

local touchable = true 

function Ontouch() -- I made the logic more compressed, and faster to write and go through/edit
    if touchable then
    p.Transparency = defaultTrans 
    touchable = false
        for i = 1, 10 - (defaultTrans * 10) do
            p.Transparency = p.Transparency + 0.1
            wait(t)
        end
        touchable = true
    end
end

p.Touched:connect(Ontouch)

I hope this helped :D

Answer this question