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
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
09:58:55.789 Workspace.Button1.ButtonActivated?:4: Expected identifier when parsing expression, got 'local' - Studio - ButtonActivated?:4
09:59:02.727 HE - Studio
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.
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
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)
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
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