Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
Gigaset39 111
1 year ago

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)
0
i just cant figure out how to do that. Gigaset39 111 — 1y
0
as you can see: ”button” and ”part” are both a Part Gigaset39 111 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago

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)
0
Thankyou, Gigaset39 111 — 1y
Ad

Answer this question