Hey Sparking!
So, with your loop, you're editing part.Transparency to be the same number over and over again, since t isn't being changed in your loop.
local touching_part = script.Parent
local debounce = false
touching_part .Touched:connect(function(part)
if(debounce == false) then
debounce = true
local t = 0
if(part.Parent:findFirstChild("Humanoid")) then
for s= 1, 10 do
part.Transparency = t + 0.1
t = t + 0.1
wait(0.5)
end
end
debounce = false
end
end)
I'd also recommend that you search for the humanoid using findFirstChildOfClass, in case your humanoid is named something different. Also, you can use your for loop to change your part's transparency a bit more easily, like so:
local touching_part = script.Parent
local debounce = false
touching_part .Touched:connect(function(part)
if(debounce == false) then
debounce = true
if(part.Parent:findFirstChildOfClass("Humanoid")) then
for s= 0, 1, 0.1 do
part.Transparency = s
wait(0.5)
end
end
debounce = false
end
end)
Avoiding HumanoidRootPart's transparency being changed is a piece of pie. Just add to your if-statement.
local touching_part = script.Parent
local debounce = false
touching_part .Touched:connect(function(part)
if(debounce == false) then
debounce = true
if(part.Parent:findFirstChildOfClass("Humanoid") and part.Name ~= "HumanoidRootPart") then
for s= 0, 1, 0.1 do
part.Transparency = s
wait(0.5)
end
end
debounce = false
end
end)
There is, however, a problem with this particular solution: With the debounce there, you can't fade more than one part at a time. So then, how do we fix this? Well, there are a couple of ways to do so, but a table will suffice.
local touching_part = script.Parent
local debounces = {}
touching_part .Touched:connect(function(part)
if(not debounces[part]) then
debounces[part] = true
if(part.Parent:findFirstChildOfClass("Humanoid") and part.Name ~= "HumanoidRootPart") then
for s= 0, 1, 0.1 do
part.Transparency = s
wait(0.5)
end
end
debounces[part] = nil
end
end)
Hope this helps! :)
1 comment
@Asker Please accept the answer for this fellow. Remember, if someone helped you, return the favour by giving him/her/apache some reputation.