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

How can I make this script not repeat every single time someone presses the button?

Asked by 7 years ago
local button = script.Parent
local elevator = button.Parent.Elevatorpiece
local ecf = elevator.Position

function onClicked(plr)
    print("elevator started")
    wait(2)
    for i = 1,52 do
    elevator.Position = elevator.Position + Vector3.new (0,.5,0)
    wait(.01)
    end
end



0
You mean like it only happens once? KingLoneCat 2642 — 7y
0
yes macabe55101 38 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Hey macabe55101,

One way that you can do what you are asking for is disabling the script, which is basically like using a boolean value to decide if the script will run or not. Simply change the script's Disable property to true at the end of the function/code block. Below is a personal example.

function do_something(x, y) -- Declaring a function with x and y paramters (They are numbers)
    print(x + y) -- Printing x + y
    script.Disabled = true -- Disabling the script so it won't work unless this is set to false
end

do_something(2, 5) -- Calling the function(Prints 7 and then gets script disabled.

Well, I hope I helped in one way or another. Have a great day/night.

~~ KingLoneCat

0
lol, thanks man macabe55101 38 — 7y
0
No problem. KingLoneCat 2642 — 7y
Ad
Log in to vote
0
Answered by
movsb 242 Moderation Voter
7 years ago

If you do not want to completely disable your script, then there is another alternative method. Assuming that you are connected to a click event, you could simply disconnect the click event.

local button = script.Parent
local elevator = button.Parent.Elevatorpiece
local ecf = elevator.Position
local onclick;
onclick = button.Click:connect(function()
    print("elevator started")
    wait(2)
    for i = 1,52 do
    elevator.Position = elevator.Position + Vector3.new (0,.5,0)
    wait(.01)
    end
    onclick:disconnect();
end);

The onclick variable must be declared before assigning it like in this example so that when you get to the line where is disconnects it does not reference a variable that does not exist.

Answer this question