Forum > Coding >

[Coding Help] how would I code a line inside my script for it to wait for a tween to end?

Nolix

use vantra hub

Posts: 375

Threads: 56

Joined: Mar, 2022

Reputation: 11

Posted

rn ive got this script which is like a grab all chests (still doesnt work that good) but I made the teleporting phase into a tween, and instead of using wait() which is kinda janky I want my script to directly pause until the tween is fully finished, how would I go by doing this?

 

current code:

game:GetService("TweenService"):Create(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart, TweenInfo.new(5, Enum.EasingStyle.Linear), { CFrame = chest.CFrame * CFrame.new(3,0,0)}):Play()
task.wait(5)
  • 0

Syraxes_

Web Developer

vip

Posts: 1068

Threads: 30

Joined: Jul, 2021

Reputation: 63

Replied

Do you want to know when the tween ends?

 

local Tween = game:GetService('TweenService'):Create....

Tween.Completed:Connect(function()
   --Stuff
end)

 

 

Roblox Docs: TweenBase#Completed

  • 0

I'm not lazy, I'm just highly motivated to do nothing. #I💚Dogs.

Nolix

use vantra hub

Posts: 375

Threads: 56

Joined: Mar, 2022

Reputation: 11

Replied

havent tested yet, but theres a 99% chance that this works, ty all! thread locked

  • 0

Added

nvm unlocking this, now I get an error "attempt to index nil with Completed" ik what that means but in the code im defining the tween so it doesnt make sense

 

local tween = game:GetService("TweenService"):Create(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart, TweenInfo.new(5, Enum.EasingStyle.Linear), { CFrame = chest.CFrame * CFrame.new(3,0,0)}):Play()
tween.Completed:Wait()
  • 0

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )