Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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



2 comments

0

You mean like it only happens once?

0

yes

2 answers

✓ Accepted answer

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

2 comments

0

lol, thanks man

0

No problem.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.