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

We need a script to activate when a button is pressed. Can anyone help us with this? [closed]

Asked by 6 years ago
Edited by BlueTaslem 6 years ago

Hello me and a friend are currently making a game but we are not scripting geniuses, so we need help to make a minigame. The minigame is Simon says and we want the script to be activated(and/or stop)when the button is pressed. Here is the script for the Simon says:

Command = script.Parent.SurfaceGui
Blue = script.Parent.Parent.Parent.Parent.Blue
Green = script.Parent.Parent.Parent.Parent.Green
Red = script.Parent.Parent.Parent.Parent.Red
Yellow = script.Parent.Parent.Parent.Parent.Yellow

wait(8)
script.Parent.Parent.Parent.Parent.Floor:Destroy()

while true do
 wait(1)
 RandNum = math.random(1, 4)

 if RandNum == 1 then
  Command.TextLabel.TextColor3 = Color3.new(0, 1, 1)
  Command.TextLabel.Text = "Stand on blue"
  wait(2)
  Green.CanCollide = false
  Red.CanCollide = false
  Yellow.CanCollide = false
  wait(2)
  Green.CanCollide = true
  Red.CanCollide = true
  Yellow.CanCollide = true

 elseif RandNum == 2 then
  Command.TextLabel.TextColor3 = Color3.new(0, 1, 0)
  Command.TextLabel.Text = "Stand on green"
  wait(2)
  Blue.CanCollide = false
  Red.CanCollide = false
  Yellow.CanCollide = false
  wait(2)
  Blue.CanCollide = true
  Red.CanCollide = true
  Yellow.CanCollide = true

 elseif RandNum == 3 then
  Command.TextLabel.TextColor3 = Color3.new(1, 0, 0)
  Command.TextLabel.Text = "Stand on red"
  wait(2)
  Green.CanCollide = false
  Blue.CanCollide = false
  Yellow.CanCollide = false
  wait(2)
  Green.CanCollide = true
  Blue.CanCollide = true
  Yellow.CanCollide = true

 elseif RandNum == 4 then
  Command.TextLabel.TextColor3 = Color3.new(1, 1, 0)
  Command.TextLabel.Text = "Stand on yellow"
  wait(2)
  Green.CanCollide = false
  Red.CanCollide = false
  Blue.CanCollide = false
  wait(2)
  Green.CanCollide = true
  Red.CanCollide = true
  Blue.CanCollide = true
  end
end

and here is the button script we are trying to attach
function onClicked(playerWhoClicked)
 script.Parent.Transparency=1
 --Put commands here
 wait(1)
 script.Parent.Transparency=0
 --If you want the command to activate after the 
 --button is pressed, put the commands here instead.
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
   end
end

and here is the button script we are trying to attach:

function onClicked(playerWhoClicked) script.Parent.Transparency=1 --Put commands here wait(1) script.Parent.Transparency=0 --If you want the command to activate after the --button is pressed, put the commands here instead. end script.Parent.ClickDetector.MouseClick:connect(onClicked)
   end
end

Any help is appreciated.

1
my gosh use a code block hiimgoodpack 2009 — 6y
0
Edited to add a code block. BlueTaslem 18071 — 6y

Closed as Not Constructive by hiimgoodpack, abnotaddable, and PyccknnXakep

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 6 years ago

Try to put that all in a function,

Then have two buttons, one to stop and one to start. remember to add a clickdetector in both the buttons also put the open and close in two different functions.

function onClicked()
    function1toopen()
end

function onClicked2()
    function2toclose()
end

button1.ClickDetector.MouseClick:connect(onClicked)
button2.ClickDetector.MouseClick:connect(onClicked2)

i'm a beginner scripter too; sorry if i wasn't much of a help.

Ad