Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make the character temporarily look at mousehit?

Asked by
soutpansa 120
6 years ago

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:

cooldown36 = 0

script.Parent.Pound36.OnServerEvent:Connect(function(Player, mousehit) 
    if Player.Stats.Stamina.Value >= 350 and Player.NonStats.Stunned.Value == false
    and Player.Character.Humanoid.Health ~= 0 and Player.NonStats.Attacking2.Value == false
    and Player.Stats.Blade.Value >= 40 and cooldown36 == 0 then
        cooldown36 = 1
        Player.NonStats.Attacking.Value = true
        Player.NonStats.Attacking2.Value = true
        Player.Stats.Stamina.Value = Player.Stats.Stamina.Value - 350
        local Fire = Player.Character.Humanoid:LoadAnimation(script.Parent.Fire)
        Player.Character.Humanoid.WalkSpeed = 0
        Fire:Play()
        local Torso = Player.Character.LowerTorso
        Torso.CFrame = CFrame.new(Torso.Position, Vector3.new(mousehit.p.X, 0, mousehit.p.Z))
        wait(1)
        Player.NonStats.Attacking2.Value = false
        if Player.NonStats.Sprint.Value == true then Player.Character.Humanoid.WalkSpeed = 30 end
        if Player.NonStats.Sprint.Value == false then Player.Character.Humanoid.WalkSpeed = 16 end
        Player.NonStats.Attacking2.Value = false
        wait(20)
        cooldown36 = 0
    end 
end)

Thanks for reading!

0
I'm having trouble with this as well. I do know that editing angles x and z will make your character fall down. You have to edit angle Y. poke7667 142 — 6y
1
I suggest you play animations on the client instead of theserver User#19524 175 — 6y
0
Playing animations from a local script needlessly complicates timing of animations. Thanks anyways soutpansa 120 — 6y

1 answer

Log in to vote
3
Answered by 6 years ago
Edited 6 years ago

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:

local direction = (mousehit.p - Player.Character.HumanoidRootPart.Position) * Vector3.new(1, 1, 1);
direction = CFrame.new(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.Position + direction)

And use the following code to make the player face that direction:

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

1
This works thanks! However, it looks a little shaky since it also moves the player down if the Y is lower than the Player's HumanoidRootPart. I changed it so mouse.hit's Y coordinate wouldn't affect the humanoidrootpart. poke7667 142 — 6y
Ad

Answer this question