Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a button that ”activates” a part just while is touched?

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)

2 comments

0

i just cant figure out how to do that.

0

as you can see: ”button” and ”part” are both a Part

1 answer

✓ Accepted answer

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)

1 comment

0

Thankyou,

This discussion is preserved as it was. New answers, comments, and votes are closed.