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

How to make when touch part, gradually fades?

So when a part is touched by a player it will fade and cannot be touched, I am getting errors saying attempt to index nil with 'Connect' (line 3)

local part = script.Parent.Roof:GetChildren()

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		while part.Tranparency > 1 do
			part.Transparency = part.Transparency - 0.001
			wait(0.001)
			repeat until part.Transparency == 0
		end
	end
end)
if part.Transparency == 0 then
	part:Destroy()
end

i still have no idea if any of this will ever work but i tried

2 comments

0

Alright, I changed my script you can check it

1

lol i would just tween it

4 answers

You need a loop for the children.

local part = script.Parent.Roof:GetChildren()
for i, child in ipairs(part) do
	child.Touched:Connect(function(hit)
	    if hit.Parent:FindFirstChild("Humanoid") then
	        while part.Tranparency > 1 do
	            part.Transparency = child.Transparency - 0.001
	            wait(0.001)
	            repeat until child.Transparency == 0
	        end
	    end
	end)
	if child.Transparency == 0 then
	    child:Destroy()
	end
end

1 comment

0

It would be a much better idea to tween. Tweening is better for performance.

use a for loop

local part = script.Parent.Roof:GetChildren()

for i, v in pairs(part) do
	for i = 0,1,0.01 do
		v.transparency = i
		wait(0.001)
	end
end

5 comments

0

thanks

0

np, pls accept answer

0

You forget () after getchildren, also this isn't an array loop, this would only work with one part.

0

Oh yeh

0

You should use tweening instead. Tweening does exactly this but it is simpler and runs better and smoother.

You can use a repeat until loop. It repeats something until it reaches a certain statement.

local part = script.Parent.Roof:GetChildren()

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
 		repeat
			wait() -- change to whatever you want
			for i, v in pairs(part) do 
				v.Transparency = v.Transparency - 0.05
			end
		until
		part.Transparency == 0
	end
end)

if part.Transparency == 0 then
	part:Destroy()
end

Also, you used the :GetChildren() function for the part variable, so you'd have to use a for in pairs loop.

Very simple :D

This is the fastest method, and much more effective than everything else :D

local Parts = script.Parent.Roof:GetChildren()

for i, v in pairs(Parts) do	
v.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
	
for i = 0,1,.1 do -- Now this acts like a while loop, it will go from 0 to 1 by 0.1 at a time get it :D
wait(0.01)
	v.Transparency = i
v:Destroy()
end
end
end)
	end
	

15 comments

0

oh nice got a dislike.

0

why would you dislike someone for trying to help lol

0

why would you dislike someone for trying to help lol

0

why would you dislike someone for trying to help lol

0

why would you dislike someone for trying to help lol

0

why would you dislike someone for trying to help lol

0

why would you dislike someone for trying to help lol

0

why would you dislike someone for trying to help lol

0

why would you dislike someone for trying to help lol

0

why would you dislike someone for trying to help lol

0

why would you dislike someone for trying to help lol

1

why would you dislike someone for trying to help lol

0

i didnt if you think it was me

0

You never solved his problem. "I am getting errors saying attempt to index nil with 'Connect' (line 3)"

0

yeah thats what i got on my original code

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