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)
01 | local part = script.Parent.Roof:GetChildren() |
02 |
03 | part.Touched:Connect( function (hit) |
04 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
05 | while part.Tranparency > 1 do |
06 | part.Transparency = part.Transparency - 0.001 |
07 | wait( 0.001 ) |
08 | repeat until part.Transparency = = 0 |
09 | end |
10 | end |
11 | end ) |
12 | if part.Transparency = = 0 then |
13 | part:Destroy() |
14 | end |
i still have no idea if any of this will ever work but i tried
You need a loop for the children.
01 | local part = script.Parent.Roof:GetChildren() |
02 | for i, child in ipairs (part) do |
03 | child.Touched:Connect( function (hit) |
04 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
05 | while part.Tranparency > 1 do |
06 | part.Transparency = child.Transparency - 0.001 |
07 | wait( 0.001 ) |
08 | repeat until child.Transparency = = 0 |
09 | end |
10 | end |
11 | end ) |
12 | if child.Transparency = = 0 then |
13 | child:Destroy() |
14 | end |
15 | end |
use a for loop
1 | local part = script.Parent.Roof:GetChildren() |
2 |
3 | for i, v in pairs (part) do |
4 | for i = 0 , 1 , 0.01 do |
5 | v.transparency = i |
6 | wait( 0.001 ) |
7 | end |
8 | end |
You can use a repeat until
loop. It repeats something until it reaches a certain statement.
01 | local part = script.Parent.Roof:GetChildren() |
02 |
03 | part.Touched:Connect( function (hit) |
04 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
05 | repeat |
06 | wait() -- change to whatever you want |
07 | for i, v in pairs (part) do |
08 | v.Transparency = v.Transparency - 0.05 |
09 | end |
10 | until |
11 | part.Transparency = = 0 |
12 | end |
13 | end ) |
14 |
15 | if part.Transparency = = 0 then |
16 | part:Destroy() |
17 | 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
01 | local Parts = script.Parent.Roof:GetChildren() |
02 |
03 | for i, v in pairs (Parts) do |
04 | v.Touched:Connect( function (hit) |
05 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
06 |
07 | 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 |
08 | wait( 0.01 ) |
09 | v.Transparency = i |
10 | v:Destroy() |
11 | end |
12 | end |
13 | end ) |
14 | end |