I am making a boss attack for my game. I am making a wave attack that comes across the island. I just don’t know how to smoothly make a part fly straight forward across the island. I just don’t know where to start. I can do the rest, thanks!
The Tween class has a .Completed() event, so you can use that.
Something like this -
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(10)
local Part = PART_TO_TWEEN_HERE
local Goal = {
CFrame = CFrame.new() -- Put a cframe here or replace it with whatever property you want to change (or add multiple properties!)
}
local Tween = TS:Create(Part, TI, Goal)
Tween:Play()
Tween.Completed:Connect(function()
-- put your function here for when the tween ends!
end)
Some more detail is here -
https://developer.roblox.com/en-us/api-reference/class/TweenService
Thanks! One quick question though, how would I move a model, would I need to play it for each individual part?
Moving a model is slightly more complex, you would need to have a CFrame value in the model for its end-state and it’s starting state and current state, you would then need to tween those values rather than the model, and have a coincidental loop running on the part using :SetPrimaryPartCFrame(), that’s how I do it with doors on my current project.
I’m currently making a slightly more sophisticated module for tweening models, though there might already be one out there, I’m unsure.
So would I do something like this?
local tweenService = game:GetService("TweenService")
local info = TweenInfo.new()
local function tweenModel(model, CF)
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = model:GetPrimaryPartCFrame()
CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local tween = tweenService:Create(CFrameValue, info, {Value = CF})
tween:Play()
tween.Completed:Connect(function()
CFrameValue:Destroy()
end)
end
This is someone else’s script, I will change it to fit what I wanna do after.
Yes, that is pretty much what I’m saying to do, obviously in the .Completed() bit you would want to destroy the part I’m assuming?