So I'm scripting a throwing knife, that tweens to the position of an invisible ball at the position of your mouse. It's hard to explain, but the throw tween looks perfect in the first couple of uses, and afterwards starts to shake as it travels through the air. It gets worse and worse after every throw, and I'm not sure why. Anyways, here's the script. Any advice or tips are appreciated
throwEvent.OnServerEvent:connect(function(player, Data)
if tool.Parent.Name ~= "Backpack" then
canSwing = false
local localGoal = CFrame.new(tool.Handle.CFrame.p, Data[1])
if localGoal ~= currentGoal then
local ray = Ray.new(tool.Handle.CFrame.p, (Data[1] - tool.Handle.CFrame.p+ Vector3.new(0, 0, 0)) * 100)
local hit, position = workspace:FindPartOnRayWithIgnoreList(ray, workspace:GetChildren())
throwingKnife = tool.Blade:clone()
throwingKnife.CFrame = throwingKnife.CFrame + throwingKnife.CFrame.lookVector
throwingKnife.knifeOwner.Value = tool.Parent.Name
throwingKnife.Parent = workspace
local distance = (script.Parent.Blade.CFrame.p - position).magnitude
local bullet = Instance.new("Part", workspace)
bullet.Material = Enum.Material.SmoothPlastic
bullet.BrickColor = BrickColor.new("White")
bullet.CanCollide = false
bullet.Anchored = true
bullet.Transparency = 1
bullet.Size = Vector3.new(0.3, 0.3, 0.3)
bullet.CFrame = CFrame.new(script.Parent.Blade.CFrame.p, position) * CFrame.new(0, 0, -distance)
bullet.Shape = "Ball"
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
local tweeningInformation = TweenInfo.new(distance/60, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false,0)
throwingKnife.RotVelocity = -throwingKnife.CFrame.rightVector*15
local partProperties = {
Position = bullet.Position;
}
Tween = TweenService:Create(throwingKnife,tweeningInformation,partProperties)
currentTween = Tween
currentGoal = localGoal
Tween:Play()
Tween.Completed:Connect(function()
if currentTween == Tween then
currentTween = nil
end
end)
throwingKnife.ThrowScript.Disabled = false
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
tool.Handle.Throw:Play()
--throwingKnife.Trail.Enabled = true
--throwingKnife.ThrowScript.Disabled = false
tool.Blade.Transparency = 1
wait(1.2)
tool.Blade.Transparency = 0
throwingKnife = nil
canSwing = true
end
end
end)

1 comment
I think it's because the first time you Tween it it has all the properties added to it, and then you're tweening it again when you throw the knife. But Idk I could be wrong.