Hi, I’m making a knockback system for my fighting game. The issue is that the character getting hit, takes too long to reach the goal. The rotating doesn’t work either. I’ve tried changing on the max force and things. Does anyone know how to fix this?
Code:
local touched = false
local TS = game:GetService("TweenService")
game.ReplicatedStorage.Throw.OnServerEvent:Connect(function(plr, mouseHit)
plr.Character.Humanoid:LoadAnimation(script.Parent.Handle:FindFirstChild("Yeet")):Play()
local clone = plr.Character:FindFirstChildWhichIsA("Tool").Handle:Clone()
clone.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= plr.Character then
if not touched then
local target = hit.Parent
local force = Instance.new("LinearVelocity",target)
local direction = (target.HumanoidRootPart.CFrame.Position - plr.Character.HumanoidRootPart.CFrame.Position).Unit
local rotation = Instance.new("AngularVelocity",target)
local ATT = Instance.new("Attachment")
ATT.Parent = target.HumanoidRootPart
force.Name = "PushForce"
force.MaxForce = math.huge
force.Attachment0 = ATT
rotation.MaxTorque = Vector3.new(1,1,1) * math.huge
rotation.Name = "angle"
touched = true
clone.CanTouch = false
clone.Impact:Play()
print(hit.Parent.Name,"was hit by",script.Parent.Name)
hit.Parent:FindFirstChild("Humanoid").Health -= 10
force.VectorVelocity = (direction + Vector3.new(0,0.25,0)).Unit * 8
rotation.AngularVelocity = Vector3.new(1,1,1) * math.pi * 2.5
force.Parent = target.HumanoidRootPart
rotation.Parent = target.HumanoidRootPart
wait(clone.Impact.TimeLength)
clone:Destroy()
touched = false
clone.CanTouch = true
--wait(0.1)
force:Destroy()
wait(1)
rotation:Destroy()
end
end
end)
wait(0.4)
plr.Character:FindFirstChildWhichIsA("Tool").Handle.Woosh:Play()
wait(0.1)
plr.Character:FindFirstChildWhichIsA("Tool").Handle.Transparency = 1
print(clone.Parent)
clone.Parent = game.Workspace
-- clone.Position = script.Parent.Handle.Position
clone.CanTouch = true
clone.CanCollide = true
clone.CFrame = plr.Character.HumanoidRootPart.CFrame+plr.Character.HumanoidRootPart.CFrame.LookVector * 5
local Tween = TS:Create(clone,TweenInfo.new(0.5),{CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.LookVector * 80})
Tween:Play()
print(mouseHit)
wait(0.45)
plr.Character:FindFirstChildWhichIsA("Tool").Handle.Transparency = 0
clone:Destroy()
end)
--clone.Touched:Connect(function(hit)
--local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
--print(plr,"was hit by",script.Parent.Name)
--end)