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

Help me with this script?[Solved]

Asked by
steev 0
10 years ago

I am trying to move a model with the TranslateBy method.

The gate moves up a few meters off the ground by a ClickDetector when the ClickDetector is clicked again it moves into its original position.

Any help?

local model = game.Workspace["MODELNAME"]; -- The model you want to move up
local part = model["MAINPART"]; -- The main part of the model (will be used as the center)
local increment = 1 --The amount you want it to go up by each time
local max = 10 --The studs you want to go up by

local closed = true;
function onClick()
    if closed then move = increment else move = -increment end
    for i=1, max/increment do
        model:TranslateBy(Vector3.new(0,move,0));
    end
end

Button.MouseClick:connect(onClick());

1 answer

Log in to vote
1
Answered by 10 years ago
local model = game.Workspace["MODELNAME"]; -- The model you want to move up
local increment = 0.5 --The amount you want it to go up by each time
local max = 10 --The studs you want to go up by
local Button = script.Parent --Change this to the ClickDetector.
local closed = true;
function onClick()
    if closed then
        move = increment 
    else 
        move = -increment 
    end 
    closed = not closed
    for i=1, max/increment do
        model:TranslateBy(Vector3.new(0,move,0));
    wait(1/60)
    end
end

Button.MouseClick:connect(onClick);

This should work, I fixed the closed variable, and fixed the nil "Button".

0
Do i put this in the button that will be clicked or the Model itself? steev 0 — 10y
0
When i start the game the model is up in the air. When i click the button the model stays there and doesn't go back down to ground. steev 0 — 10y
0
Place it in the ClickDetector. Articulating 1335 — 10y
Ad

Answer this question