Part Disappearing when touched (CollectionService)

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

I’m confused but why the touched variable and the part.Transparency property are being assigned as true or false? I see in the touched you are trying to get the value from an instance, but it’s an int value, not a boolvalue. Int is just a number that doesn’t contain decimals, and bool (or boolean) is just true or false, so instead of putting touched = false, you’re gonna put that variable a boolean value (so that it can be assiged with true or false)

local touched = Instance.new("BoolValue", workspace.HexagonSpleef.Hexagon)

and for those other assignations to touched, you’re gonna add it the Value property

touched.Value = false -- or true

And check for any other property, it should normally give an error when you try to assign to a value you aren’t meant to

Ok i have tried that but it dosen’t change the transparency and the can collide

CanCollide is a boolean by the way.

Yes I know but that still dosen’t fix the problem

Hey, i made manual and 3 tutorials cover events and instance manipulation, from what i can see you use wrong stuff and wrong types like transparency boolean or using wait instead of task.wait

also you use double touched event function which is absurd., remove one inside other, you need only first one

If you want to learn more about events and instances please read this: Scripting Manual Part 2