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 3 years ago
lua
local delay = 7

script.Parent.Touched:Connect(function(hit)
 if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
  script.Parent.Transparency = 0
  wait(1)  
  script.Parent.Transparency = 0.3
  wait(1)
  script.Parent.Transparency = 0.7
  script.Parent.CanCollide = false
--now it turns back
  wait(delay)
  script.Parent.Transparency = 0.7
  wait(1)  
  script.Parent.Transparency = 0.3
  wait(1)
  script.Parent.Transparency = 0
  script.Parent.CanCollide = true

 end
end)


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 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 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.

local delay = 7
local deb = false

script.Parent.Touched:Connect(function(hit)
    if deb == false then
        deb = true
        if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
            script.Parent.Transparency = 0
            wait(1)  
            script.Parent.Transparency = 0.3
            wait(1)
            script.Parent.Transparency = 0.7
            script.Parent.CanCollide = false
            --now it turns back
            wait(delay)
            script.Parent.Transparency = 0.7
            wait(1)  
            script.Parent.Transparency = 0.3
            wait(1)
            script.Parent.Transparency = 0
            script.Parent.CanCollide = true

            wait(.25)
            deb = false
        end
    end
end)

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

local delayTime = 7
local deb = false

script.Parent.Touched:Connect(function(hit)
    if deb == false then
        deb = true
        if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
            for i = 1, 10, 1 do
                script.Parent.Transparency = i * 0.1
                wait() -- up to you
            end
            script.Parent.CanCollide = false

            wait(delayTime)

            for i = 1, 10, 1 do
                script.Parent.Transparency = 1 - i * 0.1
                wait() -- up to you
            end
            script.Parent.CanCollide = true

            wait(.25)
            deb = false
        end
    end
end)
Ad

Answer this question