I’m trying to make a thing where the player attacks something, kinda like where the player grabs the enemy, so I try to make them face each other and play the animations, but the enemy wont face the player, it faces the same direction the player faces.
I used cframes to position and orient the player and enemy, how can I do this cuz I tried for some time and gave up
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local enemyHum = hit.Parent:FindFirstChild("Humanoid")
if enemyHum ~= hum then
vel:Destroy()
local enemy = enemyHum.Parent
local enemyHRP = enemy:FindFirstChild("HumanoidRootPart")
-- Orient the enemy to face the player
enemyHRP.CFrame = CFrame.lookAt(hrp.Position, enemyHRP.Position)
-- Move the enemy towards the player
enemyHRP.CFrame = hrp.CFrame * CFrame.new(0, 0, 5)
-- Move the player towards the enemy
task.wait(0.05)
hrp.Anchored = true
enemyHRP.Anchored = true
enemyHum.AutoRotate = false
hum.AutoRotate = false
hrp.CFrame = enemyHRP.CFrame * CFrame.new(0, 0, -0.5)
-- Stop the current animation and play the punch animation
anim:Stop()
sound:Destroy()
local punch = hum:LoadAnimation(script.Punch)
punch:Play()
local victim = enemyHum:LoadAnimation(script.Victim)
victim:Play()
-- Clean up the hitbox
hitbox:Destroy()
task.wait(1.5)
local dropkick = hum:LoadAnimation(script.Dropkick)
dropkick:Play()
end
end
end)