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

How the heck does repeat work anymore?

function myfunction()
repeat wait()
script.Parent.Parent.Glass.Position = script.Parent.Parent.Glass.Position + Vector3.new(0,0.1,0)
until script.Parent.Parent.Glass.Position >= Vector3.new(-7.43, 8.705, 21.132)
end
script.Parent.ClickDetector.MouseClick:connect(myfunction)

11 comments

0

What happens when the function runs? Does it keep on going?

0

It stops. if it is == it never stops

0

I don't know what the question is supposed to be, but on line 4, you attempt to compare 2 vectors which should yield an error.

0

Well if i make it to a == It keeps repeating Non Stop if it is <= Or >= It will not stop How do fix this?

0

As I previously stated, you cannot use comparison operators on vector3s.

0

do i remove Vector3 or add Vector2? then

0

Try comparing the Position.X, Position.Y, etc. instead of comparing the whole position to a Vector3

0

is this correct? until script.Parent.Parent.Glass.Position.Y >= (8.705)

1

Use TweenService to solve this. It is highly inefficient to adjust a position with repeat scopes. 

0

i dont know how to use Tween serivce can u just rewrite the entire script for me?

0

like @Feahren said, use TweenService. Go to youtube or somewhere to search for tutorial, this is not a free script website. There's not excuse to say "I don't know how" because there's so much information out there these days.

3 answers

✓ Accepted answer

You can use TweenService’s primary method :Create(). This method will take three arguments, the Instance we wish to perform the action on, the information regarding the Tween, which can be seen below, and the goal, what property we want to interpolate, and where to finish at. This will return a TweenObject, which we can use the :Play() method to run, and use the .Completed signal to call :Wait() on so we can tell our program to wait until we’ve reached the new position.

local TweenService = game:GetService("TweenService")

local Part = script:FindFirstAncestor("Glass")
local ClickDetector = script.Parent

local TweenInformation = TweenInfo.new(
    2 --// Length
    Enum.EasingStyle.Out -- EasingStyle
    Enum.EasingDirection.Quint --// EasingDirection
    0 --// repeat #n time(s)
    false --// should it repeat
    0 --// delay
)

local Goal = {Vector3 = Vector3.new(x,y,z)}

local Tween = TweenService:Create(Part, TweenInformation, Goal)

local function RunTween()
    Tween:Play(); Tween.Completed:Wait()
end

ClickDetector.MouseClick:Connect(RunTween)

3 comments

0

Where do i put the code?

0

In your script, just replace it

0

i will accpept this answer Since it involed Tween Serivce

Maybe use the CFrame:lerp() function. The first parameter is the target CFrame, and the second is the speed, a number between 0 and 1. This function will smoothly bring the object to the target position. Example:

part.CFrame = part.CFrame *  CFrame.new():lerp(part.CFrame * CFrame.new(1,2,3),.5)

This will smoothly bring the part 1 unit across its x axis, 2 across its y, and 3 across its z. You can also set a new part as the target, make it transparent, and use that new part as the target parameter in the function.

part.CFrame = part1.CFrame * CFrame.new():lerp(targetPart.CFrame,.5)

First,create a part, make it invisible, anchor, and turn off can collide. Then, put it where you want your glass to go.This is going to be your new part. Then your script should look like this:

local glass = script.Parent.Parent.Glass
local newPart = game.Workspace.newPart --this is your target part
function myfunction()
	glass.CFrame = glass.CFrame * CFrame.new():lerp(newPart.CFrame,.5)
end
script.Parent.ClickDetector.MouseClick:connect(myfunction)

13 comments

0

im two dumb to understand what to do lol

0

Look it up and try to understand it. If u still need help, I can rewrite your script if u need.

0

i dont know what to search two this is why i went to scriptinghelpers website i would really like that u rewrite my script(Only the repeat part of the script) thanks

0

Okay. So u shouldn't use repeat, use the lerp function. First, I want you to create a part, make it invisible, anchor it, and turn can collide off

0

Also, make it the same size as your glass part. Then, put your new part where you want the glass piece to go.

0

okay doin dat.

0

diid dat wat now

0

Okay, so now replace this with your repeat section of your script: local glass = script.Parent.Parent.Glass; glass.CFrame = glass.CFrame * CFrame.new():lerp(newPart.CFrame,.5)

0

of course, the newPart is the invisible part that I told you to put as the target

0

the newpart word has red below it?

0

the newPart is the part that i told you to create and make invisible.

0

it still inst working i renamed it and everything.

0

Make sure you have no spelling mistakes. I put your script in my answer, so maybe that should work.

im going to watch a video on how to do this So i tell everyone if it worked or not.

2 comments

0

i think i have it working

0

Okay great

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