Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to make when touch part, gradually fades?

Asked by 5 years ago

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)

01local part = script.Parent.Roof:GetChildren()
02 
03part.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
11end)
12if part.Transparency == 0 then
13    part:Destroy()
14end

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

0
Alright, I changed my script you can check it kingblaze_1000 359 — 5y
1
lol i would just tween it beargoespoopandpee 8 — 5y

4 answers

Log in to vote
1
Answered by
moo1210 587 Moderation Voter
5 years ago

You need a loop for the children.

01local part = script.Parent.Roof:GetChildren()
02for 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
15end
0
It would be a much better idea to tween. Tweening is better for performance. proqrammed 285 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

use a for loop

1local part = script.Parent.Roof:GetChildren()
2 
3for i, v in pairs(part) do
4    for i = 0,1,0.01 do
5        v.transparency = i
6        wait(0.001)
7    end
8end
0
thanks Fr0stPh3onix 79 — 5y
0
np, pls accept answer kingblaze_1000 359 — 5y
0
You forget () after getchildren, also this isn't an array loop, this would only work with one part. moo1210 587 — 5y
0
Oh yeh kingblaze_1000 359 — 5y
0
You should use tweening instead. Tweening does exactly this but it is simpler and runs better and smoother. proqrammed 285 — 5y
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

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

01local part = script.Parent.Roof:GetChildren()
02 
03part.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
13end)
14 
15if part.Transparency == 0 then
16    part:Destroy()
17end

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

Log in to vote
-2
Answered by 5 years ago
Edited 5 years ago

Very simple :D

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

01local Parts = script.Parent.Roof:GetChildren()
02 
03for i, v in pairs(Parts) do
04v.Touched:Connect(function(hit)
05    if hit.Parent:FindFirstChild("Humanoid") then
06 
07for 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
08wait(0.01)
09    v.Transparency = i
10v:Destroy()
11end
12end
13end)
14    end
0
oh nice got a dislike. maxpax2009 340 — 5y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 5y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 5y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 5y
View all comments (11 more)
0
why would you dislike someone for trying to help lol maxpax2009 340 — 5y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 5y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 5y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 5y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 5y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 5y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 5y
1
why would you dislike someone for trying to help lol maxpax2009 340 — 5y
0
i didnt if you think it was me Fr0stPh3onix 79 — 5y
0
You never solved his problem. "I am getting errors saying attempt to index nil with 'Connect' (line 3)" ScuffedAI 435 — 5y
0
yeah thats what i got on my original code Fr0stPh3onix 79 — 5y

Answer this question