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

Why is this code causing this tween to act weirdly?

Asked by 4 years ago

Made a lightsaber,

https://gyazo.com/62a3d25cbb35c54b6f96afea3ec12331

Want it to extend in a certain direction so I've tweened its size and its position by half the change in size, so it looks like it is smoothly extending upwards. However it causes this result:

https://gyazo.com/747e14062d5022b64827b16fe6d1cdcd

My code:

local tool = script.Parent
local handle = tool.Handle
local saber = tool.Saber

local TweenService = game:GetService("TweenService")
local extendinfo = TweenInfo.new(
    0.5,
    Enum.EasingStyle.Quad,
    Enum.EasingDirection.Out)

local weld = Instance.new("WeldConstraint")
weld.Part0 = handle
weld.Part1 = saber
weld.Parent = handle
saber.Transparency = 1

local Goal = {}
Goal.Size = saber.Size + Vector3.new(4,0,0)
Goal.Position = saber.Position - Vector3.new(2,0,0)

wait(3)
local Tween = TweenService:Create(saber, extendinfo, Goal)
saber.Transparency = 0
Tween:Play()

Between the first and second gif I added

Goal.Position = saber.Position - Vector3.new(2,0,0)

I'm uncertain why this is happening, as I have tried the very similar code on a singular block and it produces the result I want: https://gyazo.com/0b3930cc1121eba1e0f48d7ae3e360f3

Why might this be happening, and if so is there a way around it or to fix it?

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

While you are tweening the position you are breaking the weld, i would use C0 to position it

local tool = script.Parent
local handle = tool.Handle
local saber = tool.Saber

local TweenService = game:GetService("TweenService")
local extendinfo = TweenInfo.new(
    0.5,
    Enum.EasingStyle.Quad,
    Enum.EasingDirection.Out,
0,
false,
0)

local weld = Instance.new("WeldConstraint")
weld.Part0 = handle
weld.Part1 = saber
weld.Parent = handle
saber.Transparency = 1

local Goal = {}
Goal.Size = saber.Size + Vector3.new(4,0,0)

local Goal2 = {C0 = weld.C0*CFrame.new(saber.Position - Vector3.new(2,0,0))}
wait(3)
local Tween = TweenService:Create(saber, extendinfo, Goal)
local Tween2 = TweenService:Create(weld,extendinfo,Goal2)
saber.Transparency = 0
Tween:Play()
Tween2:Play()

Hope it works!

0
I can see where you're coming from, and see that this should be a viable way to fix the problem, but unfortunately it doesn't change anything, and produces no errors. Shrilleh 68 — 4y
0
I think what you did wrong, you forgot to add 3 last arguments maumaumaumaumaumua 628 — 4y
Ad

Answer this question