Hello, how can I make this face my mouse?

Hello, my question is simple:
How can I make my spear face my mouse?
Here’s my current code:

local S = script.ThrowingSpear:Clone() 
S.CanCollide = false
S.Anchored = false
local y = Instance.new("BodyVelocity")
y.maxForce = Vector3.new(math.huge, math.huge, math.huge) 
local SC = plr.Character.Torso.CFrame * CFrame.new(6, 0, 0)
S.CFrame = CFrame.new(SC.Position, MousePos) 
y.Velocity = S.CFrame.lookVector * 50 
S.Parent = game.Workspace 
y.Parent = S
S.PlayerName.Value = plr.Name
game.Debris:AddItem(S, 5) 

Thank you!

1 Like

Any errors showing up in the output?

Nope. nothing at all.
30 letters.

I desperately need this to work, so if anyone can help, that would be great!

Where is it currently facing? Is it 6 studs to the right of your character but is just not facing the correct direction?

Yes, it will be next to the character when the attack is used. It faces south all the time. : )

where do you define the MousePos variable? That would be the problem if that is what your seeing

I define it on a LocalScript. Which is then sent to the server Aka this script.

yes, but if you are having a problem like that the problem is how you define the variable. Are you using plr:GetMouse().Hit.p ?

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

script.AttackEvent:FireServer(Mouse.Hit.p)

It fires in the right direction, I just need it to face the mouse. : )

Thats really strange its not rotating correctly then, the shooting direction is based off of the look direction of the spear, and if its shooting in the correct direction, that must mean that its also looking in the correct direction, but its obviously not

This is obviously not going to fix it, but the only thing i can think of is replacing CFrame.new() with CFrame.lookAt() because that does a better job of what you are trying to do

Not entirely sure since I don’t work much with roblox physics, but don’t you need a BodyGyro to handle rotation?

No clue, I just thought it was Orientation based.

Okay, I’ll try to send over some code that includes a BodyGyro for you to test with.

Alrighty, thanks for this!!!
:smiley:

Okay! So, turns out, I mis-understood your question. You don’t actually need a BodyGyro
to achieve what you’re looking for, I tried it out and it automatically put the front face facing towards the direction it was moving. This makes me think that the model/mesh is actually backwards, so what you can try to do to fix this is add a

spear.CFrame = spear.CFrame * CFrame.Angles(math.rad(-180), 0, 0)

to the line before where you set the spear’s parent to the workspace. Works for me, but I’ll link my code just in case.

local player = game:GetService("Players").LocalPlayer;

local mouse = player:GetMouse();

local character = player.Character;

while true do
     if character then
          break
     end

     character = player.Character
wait()

end

wait(5)

local spear = script.ThrowingSpear:Clone()

spear.CanCollide = false;
spear.Anchored = false;

spear.Parent = game:GetService("Workspace")

local velocity = Instance.new("BodyVelocity")

velocity.maxForce = Vector3.new(math.huge, math.huge, math.huge)
velocity.Parent = spear

-- Doing this in r15 so changed "character.Torso" to "character.HumanoidRootPart"!

local cframe = character.HumanoidRootPart.CFrame * CFrame.new(6, 0, 0)
spear.CFrame = CFrame.new(cframe.Position, mouse.Hit.p)

velocity.Velocity = spear.CFrame.lookVector * 50

spear.CFrame = spear.CFrame * CFrame.Angles(math.rad(-180), 0, 0)

spear.Parent = game.Workspace
spear.PlayerName.Value = player.Name
game.Debris:AddItem(spear, 5)

return;

Hope this helps, also I did this on a localscript for the sake of simplicity, but shouldn’t be too hard to hook it up to a RemoteFunction or RemoteEvent! Hope this helps! :smiley:

cool! Thank you for this! I really appreciate it!

Of course, hope it helps! Let me know if it works!

Is there any way I can apply this to a classic script instead of a localscript? Thanks!