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
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
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
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