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

How to make a part slowly teleport/CFrame closer to player?

Asked by 4 years ago

I need to know how to make a part teleport closer or atleast CFrame closer to a player, This is very hard for me thanks for the help

my attempt

while true do
wait()
script.Parent.Position = 
 Vector3.new(+workspace.tele.Position,+workspace.tele.Position,+wokspace.tele.Position) )
end
0
try using TweenService ? I don't know if thats what you need but it may work alivemaeonman 14 — 4y
0
Yeah, TweenService would probably be your best bet. NickIsANuke 217 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

You several options. Option 1: TweenService - TweenService would be used if you want to change a property of a part gradually.

Option 2: Lerp - Lerp would ideally be used to move something back and forth, but this is not the only functionality of Lerp.

Option 3: BodyMovers - BodyMovers are nice for projectiles, but can potentially lag.

TweenService - To use TweenService, you'd first have to initialize TweenService.

local tweenService = game:GetService("TweenService");

Then, you'd want to create a new TweenInfo. You could even have a default one just by having the parameter be TweenInfo.new(), but lets create one.

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut); -- You can change these to however you want.

You can find more info on TweenInfo.new() here: https://developer.roblox.com/en-us/api-reference/datatype/TweenInfo

Now, we need to create a new Tween, and make it for the part.

local Goal = {
  CFrame = CFrame.new(0, 0, 0); -- Change this CFrame.new(0, 0, 0); to the position of the player's character's HumanoidRootPart, then if you want it to have an offset, multiply.
}

local Tween = tweenService:Create(part, tweenInfo, Goal);

Tween:Play(); 

Full code:

local tweenService = game:GetService("TweenService");
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut); -- You can change these to however you want.
local Goal = {
  CFrame = CFrame.new(0, 0, 0); -- Change this CFrame.new(0, 0, 0); to the position of the player's character's HumanoidRootPart, then if you want it to have an offset, multiply.
}

local Tween = tweenService:Create(part, tweenInfo, Goal);

Tween:Play(); 

Now, you'd probably want to incorporate this into a loop. If you're using a LocalScript, use the .RenderStepped event of RunService (more info here: https://developer.roblox.com/en-us/api-reference/event/RunService/RenderStepped)

If you're using a ServerScript for whatever reason, use a while wait() do loop. I personally think AlvinBlox covered it nice enough here: https://youtu.be/qgGDwTn0zgo

For Option 3 (BodyMovers), you could use AlignPosition, or BodyPosition. I personally would suggest using AlignPosition.

Please mark this as the answer/upvote if I've helped you with your question, and feel free to ask any questions in the comments.

0
This is good tho, I feel my grammar sucks so much, also upvoted Xapelize 2658 — 4y
0
Thank you Jack. GeneratedScript 740 — 4y
Ad

Answer this question