Hello!
I am trying to make a part disappear with a gradient when the part is touched. But what I have encountered was that the part wouldn’t disappear when it is touched but then just made me fall through. Any Help?
Explanation of Code:
In this script I added a intvalue with the name of Touched and put it to false. Then I identified whether if the thing that touched the part was a roblox player. After that it checked if the player has touched the part and if it did it would put touched to true and then it would have a while loop to gradually decrease the transparency. After that It checked if the player has stopped touching the part and it would put touched to false.
Script:
local touched = Instance.new("IntValue", workspace.HexagonSpleef.Hexagon)
touched = false
local CollectionService = game:GetService("CollectionService")
for _, part in CollectionService:GetTagged("DissapearBrick") do
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and touched == false then
part.Touched:Connect(function()
touched = true
print("Touched")
while part.Transparency >= 0 do
part.Transparency -= 0.1
wait(0.1)
part.CanCollide = false
wait(0.1)
if part.Transparency == 0.1 then
touched = false
wait(3)
part.Transparency = true
part.CanCollide = true
end
end
if touched == true then
wait(0.1)
touched = false
end
end)
part.TouchEnded:Connect(function()
touched = false
print("UnTouched")
end)
end
end)
end