Hello world! Im creating a 2 player obby:
How to make a Button that turns a part to Transparency = 0 and CanCollide = true just while is touched? soo , as soon as the player doesent touch anymore that Button, the Part whil go back to Transparency = 0.6 and CanCollide = false.
Curently i use this:
local button = script.Parent.Button local part = script.Parent.Part local Debounce = false script.Parent.Button.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if Debounce == false then Debounce = true button. BrickColor = BrickColor.new ("Bright red") part.Transparency = 0 part.CanCollide = true wait(20) button.BrickColor = BrickColor.new("Bright green") part.Transparency = 0.6 part.CanCollide = false Debounce = false end end end)
You can use the Part.TouchEnded
event which detects if a part un-touches the part.
local button = script.Parent.Button local part = script.Parent.Part button.Touched:Connect(function(hit) if hit.Parent:FindFirstChildOfClass("Humanoid") then button.BrickColor = BrickColor.new("Bright red") part.Transparency = 0 part.CanCollide = true end end) button.TouchEnded:Connect(function(hit) if hit.Parent:FindFirstChildOfClass("Humanoid") then button.BrickColor = BrickColor.new("Bright green") part.Transparency = 0.6 part.CanCollide = false end end)