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

Is this a valid script to make a part visible then...?

Asked by 4 years ago
01lua
02local delay = 7
03 
04script.Parent.Touched:Connect(function(hit)
05 if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
06  script.Parent.Transparency = 0
07  wait(1
08  script.Parent.Transparency = 0.3
09  wait(1)
10  script.Parent.Transparency = 0.7
11  script.Parent.CanCollide = false
12--now it turns back
13  wait(delay)
14  script.Parent.Transparency = 0.7
15  wait(1
View all 22 lines...

What it's supposed to do is make it slightly invisible and doesn't collide then collides and is visible again (When you hit it). Does it work?

0
I tried and it doesnt work. Is there a thing wrong? jmathewbat -13 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I tested this and it's working but, I'm assuming you are trying to make it slightly invisible and uncollideable then after a period of time it goes back to normal right?

Then you need to add debounce! To prevent multiple action while one is running.

The reason it doesn't work as it supposed to do is because when you try to go through the door, your character will be touching the part and runs your touched event.

01local delay = 7
02local deb = false
03 
04script.Parent.Touched:Connect(function(hit)
05    if deb == false then
06        deb = true
07        if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
08            script.Parent.Transparency = 0
09            wait(1
10            script.Parent.Transparency = 0.3
11            wait(1)
12            script.Parent.Transparency = 0.7
13            script.Parent.CanCollide = false
14            --now it turns back
15            wait(delay)
View all 27 lines...

FYI: You can use for i loop to change transparency of your part, etc for a smooth effect. Example:

01local delayTime = 7
02local deb = false
03 
04script.Parent.Touched:Connect(function(hit)
05    if deb == false then
06        deb = true
07        if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
08            for i = 1, 10, 1 do
09                script.Parent.Transparency = i * 0.1
10                wait() -- up to you
11            end
12            script.Parent.CanCollide = false
13 
14            wait(delayTime)
15 
View all 26 lines...
Ad

Answer this question