So I was wondering whether I can use LookVector in this manner:
MjolnirClone.Velocity = (CFrame.new(MjolnirClone.Position,Vector3.new(MousePosition.X, MousePosition.Y, MousePosition.Z)).LookVector * 300)
Or will it error and why?
So I was wondering whether I can use LookVector in this manner:
MjolnirClone.Velocity = (CFrame.new(MjolnirClone.Position,Vector3.new(MousePosition.X, MousePosition.Y, MousePosition.Z)).LookVector * 300)
Or will it error and why?
The code is really long and confusing, let’s first cut it down a bit so it’s clearer.
MjolnirClone.Velocity = CFrame.new(MjolnirClone.Position, MousePosition).LookVector*300
Much better.
Yes, this is fine, since CFrames have a LookVector property and that is the forward direction of the CFrame. Then you are multiplying by 300 so it goes 300 studs fast.
Although you could have tested this yourself to avoid having to ask people to do it for you
This error pops up when I try this "ServerScriptService.Mjolnir Attacks:24: invalid argument #2 to ‘new’ (Vector3 expected, got nil) "
That means MousePosition is nil – make sure you have it declared somewhere
I have the parameter in this function:
HammerThrow.OnServerEvent:Connect(function(Player,MousePosition)
local Torso = Player.Character:FindFirstChild("Torso") or Player.Character:FindFirstChild("HumanoidRootPart")
Mjolnir.Handle.Transparency = 1
local MjolnirClone = Mjolnir.Handle:Clone()
MjolnirClone.Parent = workspace
MjolnirClone.CanCollide = true
MjolnirClone.CFrame = Mjolnir.Handle.CFrame
MjolnirClone.Velocity = CFrame.new(MjolnirClone.Position, MousePosition).LookVector * 300
end)
That is fired from the mouse’s hit.position in the local script:
Mjolnir.Activated:Connect(function()
if Throwable then
Throwable = false
LoadHammerThrowAnimation:Play()
LoadHammerThrowAnimation.KeyframeReached:Connect(function(KeyFrame)
if KeyFrame == "LaunchThrow" then
HammerThrow:FireServer(Mouse.Hit.p)
LoadHammerThrowAnimation:Stop()
end
What else am I missing here?