Tween CFrame.Position not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a knockback for my character
  2. What is the issue? Include screenshots / videos if possible!
    It would tween the enemy spin or sometimes stay idle after the tween is finished
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes I did look for some solution but there isn’t any solution I found
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

This is the coding

game.ReplicatedStorage.MakeKnockback.OnClientEvent:Connect(function(enemy:Model,knocker:Model,duration:DoubleConstrainedValue)
	local playertorso=knocker.HumanoidRootPart
	local EnemyTorso=enemy.HumanoidRootPart
	local Tween=TweenS:Create(EnemyTorso,TweenInfo.new(100,Enum.EasingStyle.Cubic),{Position=playertorso.CFrame*CFrame.new(0,0,-1000).Position})
	Tween:Play()
	local lookvector=(playertorso.Position-EnemyTorso.Position).Unit
	EnemyTorso.CFrame=CFrame.new(EnemyTorso.Position,EnemyTorso.Position+lookvector)
	local knockbackdirection=lookvector*Vector3.new(1,0,1)
	local shockwave=game.ReplicatedStorage.Wave:Clone()
	shockwave.CFrame=EnemyTorso.CFrame
	shockwave.Parent=enemy
	shockwave.Orientation=playertorso.Orientation+Vector3.new(0, 78.2, 90)
	local TS=game:GetService("TweenService")
	local Tweensize=TS:Create(shockwave,TweenInfo.new(1),{Size=Vector3.new(10,0,10);Transparency=1})
	Tweensize:Play()
	task.wait(duration)
	Tween:Cancel()
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

game.ReplicatedStorage.MakeKnockback.OnClientEvent:Connect(function(enemy:Model,knocker:Model,duration:DoubleConstrainedValue)
	local playertorso=knocker.HumanoidRootPart
	local EnemyTorso=enemy.HumanoidRootPart
	local Tween=TweenS:Create(EnemyTorso,TweenInfo.new(100,Enum.EasingStyle.Cubic),{Position=(playertorso.CFrame*CFrame.new(0,0,-1000)).Position}) -- adding brackets would solve it.
	Tween:Play()
	local lookvector=(playertorso.Position-EnemyTorso.Position).Unit
	EnemyTorso.CFrame=CFrame.new(EnemyTorso.Position,EnemyTorso.Position+lookvector)
	local knockbackdirection=lookvector*Vector3.new(1,0,1)
	local shockwave=game.ReplicatedStorage.Wave:Clone()
	shockwave.CFrame=EnemyTorso.CFrame
	shockwave.Parent=enemy
	shockwave.Orientation=playertorso.Orientation+Vector3.new(0, 78.2, 90)
	local TS=game:GetService("TweenService")
	local Tweensize=TS:Create(shockwave,TweenInfo.new(1),{Size=Vector3.new(10,0,10);Transparency=1})
	Tweensize:Play()
	task.wait(duration)
	Tween:Cancel()
end)

It would make the humanoidrootpart go only,not the whole character

Wow thats weird. Try using lerp or something.

Why not just use :MoveTo?

I’m making knockback,not either teleporting or ai

My apologies, Idk why I posted that reply.

Now back to the topic, using tweens is a horrible idea as you lose out on physics behavior of Roblox, and as such collisions won’t be accounted when performing kb.

It’s better to call ApplyImpulse on the root part of the character as it respects collsions. In your case, smth like this should work:

local playerTorso=knocker.HumanoidRootPart
local enemyTorso = enemy.HumanoidRootPart
enemyTorso:ApplyImpulse(playerTorso.CFrame.LookVector * 1000)

I fixed it lol,but thanks for the help,it do works too since I used it in another game!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.