Button Activator Isn't working

Hello! I’m trying to make a 2 player obby ( TWMTDW ) but I tried to code my own button and make it so that the player cant spam it and it has a delay but it doesn’t work at all, and also nothing comes in the output so I cant find the problem.

ButtonActivated? >>>>

local Button1 = script.Parent

local function PressedButton()
	Button1.BrickColor = BrickColor.new("Lime green")
	game.Workspace.ButtonActivatingPart1.ButtonPressed.Value = true
	wait(4)
	game.Workspace.ButtonActivatingPart1.ButtonPressed.Value = false
	Button1.BrickColor = BrickColor.new("Dark stone grey")
end

if Button1.Touched then
	wait(2)
	Button1.Touched:Connect(PressedButton)
end

ButtonActivatedHandler >>>>

local ButtonActivatingPart = script.Parent

if game.Workspace.Button1.BrickColor == BrickColor == ("Lime green") then
	ButtonActivatingPart.CanCollide = true
	ButtonActivatingPart.Transparency = 0
	wait(4)
	ButtonActivatingPart.CanCollide = false
	ButtonActivatingPart.Transparency = 0.5
end
2 Likes

I am confusion

Touched is an event, you don’t need to check for a conditional statement all you really need to do is connect it

You’re attempting to equal an unknown global variable, when you should be doing BrickColor.new() to create a new BrickColor value

This should fix it:

local Button1 = script.Parent

local function PressedButton()
	Button1.BrickColor = BrickColor.new("Lime green")
	game.Workspace.ButtonActivatingPart1.ButtonPressed.Value = true
	wait(4)
	game.Workspace.ButtonActivatingPart1.ButtonPressed.Value = false
	Button1.BrickColor = BrickColor.new("Dark stone grey")
end

wait(2)
Button1.Touched:Connect(PressedButton)
local ButtonActivatingPart = script.Parent

if game.Workspace.Button1.BrickColor == BrickColor.new("Lime green") then
	ButtonActivatingPart.CanCollide = true
	ButtonActivatingPart.Transparency = 0
	wait(4)
	ButtonActivatingPart.CanCollide = false
	ButtonActivatingPart.Transparency = 0.5
end
1 Like

doesnt work when I tested it inside the game

Well, the second code you have would fire instantly cause there’s no function or wait inside it which would instantly pass it’s changes

Did you mean to create a function to detect when the ButtonActivatingPart gets touched?

1 Like

Yes


I don’t see why you need two scripts for detecting when a part is touched. Try this script:

local Button1 = script.Parent
local ButtonActivatingPart = -- reference the part to activate

local function PressedButton()
    -- activates the part
	Button1.BrickColor = BrickColor.new("Lime green")
	ButtonActivatingPart.CanCollide = true
	ButtonActivatingPart.Transparency = 0

	wait(4)

    -- deactivates the part
	ButtonActivatingPart.CanCollide = false
	ButtonActivatingPart.Transparency = 0.5
	Button1.BrickColor = BrickColor.new("Dark stone grey")
end

wait(2)
Button1.Touched:Connect(PressedButton) -- triggers the function in the parentheses when touched

2 Likes
  09:58:55.789  Workspace.Button1.ButtonActivated?:4: Expected identifier when parsing expression, got 'local'  -  Studio - ButtonActivated?:4
  09:59:02.727  HE  -  Studio

Oh, I was also making a button game and I had the same problem, but I fixed it.
I think this should fix your script.

Why would I want the script disabled? The players should be able to activate it all of the time, if they activate it once and the other player on the other side either falls or doesn’t make it in time then the levels just impossible.

I’m super confused rightnow Touched is an event

But this would stop the spamming of the button.

But at the same time, it just makes the game completely impossible, that’s like a 1 time thing and then players would have to rejoin and hope that the other player didn’t alr click the button and they know what their doing

Does this work?

local Button1 = script.Parent

local function PressedButton()
	Button1.BrickColor = BrickColor.new("Lime green")
	game.Workspace.ButtonActivatingPart1.ButtonPressed.Value = true
	Button1.CanCollide = true
	Button1.Transparency = 0
	wait(4)
	game.Workspace.ButtonActivatingPart1.ButtonPressed.Value = false
	Button1.BrickColor = BrickColor.new("Dark stone grey")
	Button1.CanCollide = false
	Button1.Transparency = 0.5
end

Button1.Touched:Connect(PressedButton)
1 Like

No, Because you keep refrencing button1 which is supposed to activate the platform on the other side

Are the parents of the scripts the same things or are they two different things?

Two Diffrent things


My PC crashed :confused:

Use a debounce

local Button1 = script.Parent
local DB = false

local function PressedButton()
    if not DB then
        DB = true
	Button1.BrickColor = BrickColor.new("Lime green")
	  game.Workspace.ButtonActivatingPart1.ButtonPressed.Value = true
	wait(4)
	DB = false 
game.Workspace.ButtonActivatingPart1.ButtonPressed.Value = false
	Button1.BrickColor = BrickColor.new("Dark stone grey")
    end
end

wait(2)
Button1.Touched:Connect(PressedButton)
local ButtonActivatingPart = script.Parent
local DB = false

local function CheckButton()
if game.Workspace.Button1.BrickColor == BrickColor.new("Lime green") and not DB then
        DB = true
	ButtonActivatingPart.CanCollide = true
	ButtonActivatingPart.Transparency = 0
	wait(4)
        DB = false
	ButtonActivatingPart.CanCollide = false
	ButtonActivatingPart.Transparency = 0.5
 end
end

ButtonActivatingPart.Touched:Connect(CheckButton)

Excuse the formatting, on mobile

2 Likes
  10:12:41.855  ButtonPressed is not a valid member of Part "Workspace.ButtonActivatingPart1"  -  Server - ButtonActivated?:8
  10:12:41.856  Stack Begin  -  Studio
  10:12:41.856  Script 'Workspace.Button1.ButtonActivated?', Line 8 - function PressedButton  -  Studio - ButtonActivated?:8
  10:12:41.857  Stack End  -  Studio

Its actually called ButtonActivatedPart1

local Button1 = script.Parent
local ButtonActivatingPart = workspace:WaitForChild("ButtonActivatedPart1") -- change location if wrong
local debounce = false

local function PressedButton()
    if not debounce then
        debounce = true
        -- activates the part
	    Button1.BrickColor = BrickColor.new("Lime green")
	    ButtonActivatingPart.CanCollide = true
	    ButtonActivatingPart.Transparency = 0

	    wait(4)

        -- deactivates the part
	    ButtonActivatingPart.CanCollide = false
	    ButtonActivatingPart.Transparency = 0.5
	    Button1.BrickColor = BrickColor.new("Dark stone grey")
        debounce = false
    end
end

wait(2)
Button1.Touched:Connect(PressedButton) -- triggers the function in the parentheses when touched
1 Like