Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i make a player face the direction the mouse?

I have a script where you hold E, an animation play's and fire's a ki blast. But the character isn't facing the way the ki blast is. Is there a way i can make it so the player face's the same way as the mouse, or the ki blast?

I'm not good with scripting a player's position, so if someone can give me a quick example of how to do it, please do. Im using UIS for the script btw

1 answer

✓ Accepted answer

Yes, we can change the cframe of the character's primarypart (humanoidrootpart).

We will do something like this

--[[the humanoidrootpart]].CFrame=CFrame.new(--[[position]],--[[direction]])

We will use the SetPrimaryPartCFrame function of model to do this.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local mouse = plr:GetMouse()

char:SetPrimaryPartCFrame(CFrame.new(char.HumanoidRootPart.Position,mouse.Hit.p))

This is inside a LocalScript

The CFrame I gave to the primary part was at the humanoidrootpart's location looking towards the mouse's postion.

This discussion is preserved as it was. New answers, comments, and votes are closed.