Make projectile face mouse

help making projectile face mouse.

code: local tool = script.Parent

tool.Activated:Connect(function()
local projectile = script.Parent.Handle.projectile:Clone()
local toolh = script.Parent.Handle

local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local mpos = plr.PlayerGui.MousePos

print(mpos.Value)

projectile.Parent = plr.Character
projectile.CFrame = toolh.CFrame
projectile.Orientation = toolh.Orientation

end)``

oh yeah i removed the cframe lookat part, it did nothing even tho it should

If this is a server script you can try getting the mouse Hit position from the client through a remote event, and then set the cframe of the projectile on the server. You also need to make sure that the long axis of the projectile is the Z axis.

local script:

local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
tool.Activated:Connect(function()
    tool.RemoteEvent:FireServer(mouse.Hit.Position)
end)

server script:

tool.RemoteEvent.OnServerEvent:Connect(function(plr, mousePos)
    local projectile = script.Parent.Handle.projectile:Clone()
    projectile.Parent = plr.Character
    projectile.CFrame = CFrame.new(script.Parent.Handle.Position, mousePos)
end)

same result as before it spawns but the direction is opposite like if i shoot front it goes sideways and if i shoot sideways it goes front…

you need to make sure the projectile is long on the Z axis

Maybe you can try setting up an initial position first then adjust the orientation:

tool.RemoteEvent.OnServerEvent:Connect(function(plr, mousePos)
    local projectile = script.Parent.Handle.projectile:Clone()
    projectile.Parent = por.Character
    projectile.CFrame = CFrame.new(script.Parent.Handle.Position)
    projectile.CFrame = CFrame.new(projectile.Position, mousePos)
end)

nop, i fixed it by using angles(0,math,rad(87),0)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.