Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

1 comment

0

I tried and it doesnt work. Is there a thing wrong?

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.