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

How do I make this work more than once?

Asked by 10 years ago

Apparently this only works once. Im not sure why

enabled = true

function onTouched(hit)
    local door1=script.Parent.Parent.Door1
    local door2=script.Parent.Parent.Door2
h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil then
if not enabled then return end
enabled = false
door1.CanCollide=false
door2.CanCollide=false
for i=1,10 do
    wait()

door1.Transparency=door1.Transparency+.1
door2.Transparency=door2.Transparency+.1



end
wait(4)
for i=1,20 do
    wait()

door1.Transparency=door1.Transparency-.1
door2.Transparency=door2.Transparency-.1


end
door1.CanCollide=true
door2.CanCollide=true
enabled = true
end
end

connection = script.Parent.Touched:connect(onTouched)
0
Does it work? HexC3D 830 — 10y
0
Try it again HexC3D 830 — 10y
0
Fixed it. HexC3D 830 — 10y

2 answers

Log in to vote
2
Answered by
HexC3D 830 Moderation Voter
10 years ago
val = 0
time = 0
function onTouched(hit)
    local door1=script.Parent.Parent.Door1
    local door2=script.Parent.Parent.Door2
h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil then
val = 1
if val == 1 then
val = 0
door1.CanCollide=false
door2.CanCollide=false
for i=1,10 do
    wait()

door1.Transparency=door1.Transparency+.1
door2.Transparency=door2.Transparency+.1



end
wait(4)
for i=1,10 do
    wait()

door1.Transparency=door1.Transparency-.1
door2.Transparency=door2.Transparency-.1


end
door1.CanCollide=true
door2.CanCollide=true
end
end
end



script.Parent.Touched:connect(onTouched)

You don't need enabled though tell in the comments if it works.

+1 if helped.

0
The enabled is debounce.. Tempestatem 884 — 10y
0
But, it still should work. I don't use debounce honestly. HexC3D 830 — 10y
0
But its on touch, so it will freak out or somthing? Tempestatem 884 — 10y
0
Oh you mean so if some one touches it more then once. HexC3D 830 — 10y
View all comments (13 more)
0
Yeah it breaks.. Tempestatem 884 — 10y
0
As in, after a few times, it doesnt work Tempestatem 884 — 10y
0
But try again HexC3D 830 — 10y
0
It works, but still after a while it stops working? Tempestatem 884 — 10y
0
How many times. HexC3D 830 — 10y
0
It works 2 times, then stops working. Tempestatem 884 — 10y
0
I tested your debounce with a "print" and it doesnt work. Tempestatem 884 — 10y
0
Try again please sorry for the inconvenience HexC3D 830 — 10y
0
no problem! I upped your post btw. Tempestatem 884 — 10y
0
Thanks :) HexC3D 830 — 10y
0
Oh! I checked in game, and it keeps subtracting the 0.1 from it, after the second time for some reason Tempestatem 884 — 10y
0
I FIGURED IT OUT !!! HexC3D 830 — 10y
0
Thankyeverymuch Tempestatem 884 — 10y
Ad
Log in to vote
-1
Answered by
foxy83 15
10 years ago

Have you tried the loop or wait?

wait(2) --if a function but the function there ex: Fire()
fire()
end

Answer this question