I want the character to look where the mouse is pointing for a few seconds, but when I try it, it just makes the player fall down. Like this
Here is the code that I'm using:
01 | cooldown 36 = 0 |
02 |
03 | script.Parent.Pound 36. OnServerEvent:Connect( function (Player, mousehit) |
04 | if Player.Stats.Stamina.Value > = 350 and Player.NonStats.Stunned.Value = = false |
05 | and Player.Character.Humanoid.Health ~ = 0 and Player.NonStats.Attacking 2. Value = = false |
06 | and Player.Stats.Blade.Value > = 40 and cooldown 36 = = 0 then |
07 | cooldown 36 = 1 |
08 | Player.NonStats.Attacking.Value = true |
09 | Player.NonStats.Attacking 2. Value = true |
10 | Player.Stats.Stamina.Value = Player.Stats.Stamina.Value - 350 |
11 | local Fire = Player.Character.Humanoid:LoadAnimation(script.Parent.Fire) |
12 | Player.Character.Humanoid.WalkSpeed = 0 |
13 | Fire:Play() |
14 | local Torso = Player.Character.LowerTorso |
15 | Torso.CFrame = CFrame.new(Torso.Position, Vector 3. new(mousehit.p.X, 0 , mousehit.p.Z)) |
Thanks for reading!
There's an easy way to make the player face where the mouse is pointing for a few seconds.
If everything is working, but the character is falling, then it is because the HumanoidRootPart of the Character isn't Anchored. Make sure you do Player.Character.HumanoidRootPart.Anchored = true
, if everything isn't working, I made my own code that MIGHT work.
If the only problem is the character falling, then simply anchor the HumanoidRootPart, otherwise:
Use the following code to get the direction:
1 | local direction = (mousehit.p - Player.Character.HumanoidRootPart.Position) * Vector 3. new( 1 , 1 , 1 ); |
2 | direction = CFrame.new(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.Position + direction) |
And use the following code to make the player face that direction:
1 | Player.Character.HumanoidRootPart.CFrame = direction |
Please let me know what works and what doesn't, leave a comment if something's wrong or if you're confused. Be sure to accept my answer if I solved your question and help a guy out :3 Good luck