Im trying to make an elevator but i need help with scripting it

how do i turn this into a script were if you click a button then the part will go up until it hits a certain part then it stop but if the player clicks the other button it will either stop or go down depending if the elevator goes up or not.
local elevator = script.Parent.Parent.elevatorpart

local button = script.Parent

local clickdetector = script.Parent.ClickDetector

local button2 = script.Parent.Parent.down.ClickDetector

clickdetector.MouseClick:Connect(function()

end)

You can use tween Service for elevator. TweenService | Documentation - Roblox Creator Hub

is there another way on moving it up instead of doing vector3.new()?

because vector3.new() is easy to use but i wanted to use another method for when i duplicate the elevator

Tween Example:

local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(5,Enum.EasingStyle.Linear ,Enum.EasingDirection.In)--(Time, EasingSyle,EasingDirection)
local part = script.Parent
local propertyTable = {Position = Vector3.new(-8.715, 40.5, -3.855)}--It will move to that position
local Tween = tweenService:Create(part,tweenInfo,propertyTable)
Tween:Play()

yea ik but when i duplicate it and put it to other places cause im making a tycoon i dont want the elevator being in the same spot when it goes up

like for example “elevator.position = elevator.postion + (0,4,0)” would that work?

Yes, that would work, but you’d have to implement that into a tween, otherwise the elevator will just teleport up without keeping the players inside of it.

You can just add number to Y axis and try to get the perfect number:

    local part = script.Parent
    local goal = Vector3.new(part.Position.X,part.Position.Y + 20 ,part.Position.Z)--Change number 20
--------or
    local goal = script.Parent.Position + Vector3.new(0,20,0)

No it wont work like that. I put the example how to add like the Y axis value.

Along with this, as you said in the original post, you can even use the ending part’s position to set the goal of the Tween.

local a = script.Parent.Position + Vector3.new(0,4,4)

print(a) -- It will print with no error

local p = script.Parent.Position + (4,4,4)

print(p) -- Error
1 Like

know what frik it, its too confusing to me imma just use vector3.new() cause thats easier instead of the stuff thats more confusing.

1 Like

Please do not use Tween Service, it’s just not good, either makes sense, and it would causes trouble like glitching and more.
use prismatic constraists

1 Like

Your elevator will teleport. That mean players won’t move with the elevator they will stay at the same position.

1 Like

unless you do this over and over again

elevator.position = vector3.new(-- number example)
elevator.position = vector3.new(-- number example)
elevator.position = vector3.new(-- number example)
elevator.position = vector3.new(-- number example)
elevator.position = vector3.new(-- number example)

1 Like

Just use for loop instead. If you can’t understand tweening.

Example:
local goal = 20
for i = 1, goal, 0.5 do
script.Parent.Position = script.Parent.Position + Vector3.new(0,i,0)
wait(0.1)–Time
end

2 Likes

the elevator went somewere but i don’t know were all i know is it did not go up
robloxapp-20200804-1350240.wmv (1.1 MB)
local elevator = script.Parent.Parent.elevatorpart
local button = script.Parent
local clickdetector = script.Parent.ClickDetector
local button2 = script.Parent.Parent.down.ClickDetector

clickdetector.MouseClick:Connect(function()
local goal = 90
for i = 1, goal, 0.5 do
elevator.Position = elevator.Position + Vector3.new(0,i,0)
end
end)

1 Like

Put wait I forgot to put wait I just edited it

1 Like

Also, you can change 0.5 to 0.1 to make it smoother

1 Like