How do i add tween service to this script? plz help

how do i add tween service to this?:
local elevator = script.Parent.Parent.elevatorpart

local button = script.Parent

local clickdetector = script.Parent.ClickDetector

local button2 = script.Parent.Parent.down

local buttonstand = script.Parent.Parent.buttonstand

clickdetector.MouseClick:Connect(function()

local goal = 2.3

for i = 1.7, goal, 0.1 do

elevator.Position = elevator.Position + Vector3.new(0,i,0)

wait(0.4)–Time

end

end)

clickdetector.MouseClick:Connect(function()

local goal = 2.3

for i = 1, goal, 0.1 do

script.Parent.Position = script.Parent.Position + Vector3.new(0,i,0)

wait(0.1)–Time

end

end)

clickdetector.MouseClick:Connect(function()

local goal = 2.3

for i = 1, goal, 0.1 do

button2.Position = button2.Position + Vector3.new(0,i,0)

wait(0.1)–Time

end

end)

clickdetector.MouseClick:Connect(function()

local goal = 2.3

for i = 1, goal, 0.1 do

buttonstand.Position = buttonstand.Position + Vector3.new(0,i,0)

wait(0.1)–Time

end

end)

Scripting support is not somewhere where you ask for people to write code for you.
You should also indent your code to make it readable.

1 Like

well then were is a place? i tried discord and that don’t work and i tried here and it did work

Here is some example code that you should be able to use to replace your for loops:

local TweenService = game:GetService("TweenService")
 
local tweenInfo = TweenInfo.new(
	2, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)
 
Part = buttonstand
local tween1 = TweenService:Create(Part, tweenInfo, {Position = Vector3.new(0, 10, 20)})
tween1:Play()

This tweens “Part”, to the Vector3 position inside the TweenService:Create()

Resources:

Also, for future reference, it’s really appreciated if you wrap your code with ```, so that is is more readable.

Try Scripting Helpers, just try not to make it sound like you’re requesting code.

1 Like

is there such thing as “tween1:Pause()” ?
or “tween1:Stop()” ?

As you can see from the Tween developer hub page, the functions are the following.

Tween:Pause() --pauses the tween

Tween:Cancel() --stops the tween, and will start from the beginning if played again
1 Like