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

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

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

4 answers

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

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
0
It would be a much better idea to tween. Tweening is better for performance. proqrammed 285 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
0
thanks Fr0stPh3onix 79 — 4y
0
np, pls accept answer kingblaze_1000 359 — 4y
0
You forget () after getchildren, also this isn't an array loop, this would only work with one part. moo1210 587 — 4y
0
Oh yeh kingblaze_1000 359 — 4y
0
You should use tweening instead. Tweening does exactly this but it is simpler and runs better and smoother. proqrammed 285 — 4y
Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

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.

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

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

0
oh nice got a dislike. maxpax2009 340 — 4y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 4y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 4y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 4y
View all comments (11 more)
0
why would you dislike someone for trying to help lol maxpax2009 340 — 4y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 4y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 4y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 4y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 4y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 4y
0
why would you dislike someone for trying to help lol maxpax2009 340 — 4y
1
why would you dislike someone for trying to help lol maxpax2009 340 — 4y
0
i didnt if you think it was me Fr0stPh3onix 79 — 4y
0
You never solved his problem. "I am getting errors saying attempt to index nil with 'Connect' (line 3)" ScuffedAI 435 — 4y
0
yeah thats what i got on my original code Fr0stPh3onix 79 — 4y

Answer this question