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

"bad #2 argument to 'new' (Vector3 expected, got object)" Error to mouse.Hit.Position?

Asked by 5 years ago
Edited 5 years ago

In my new game, I was trying to make a gun that would face your mouse cursor, but it keeps returning the error stated in the title despite mouse.Hit.Position being a Vector3. (Before anyone asks, Position and p are both valid.)

My serverside is

local Facing = script.Parent
local CenterBrick = game.Workspace:WaitForChild("MamiMusket").Centeral

Facing.OnServerEvent:Connect(function(mouseHit)
    CenterBrick.CFrame = CFrame.new(CenterBrick.Position, mouseHit)
end)

and my clientside is

local LP = game.Players.LocalPlayer
local mouse = LP:GetMouse()
local remote = game.Workspace.MamiMusket.Center.Facing``
while wait() do
    remote:FireServer(Vector3.new(mouse.Hit.Position))
end

My serverside script shares the parent with the remoteEvent while my clientside is parented to starterGui. I know that, that will be a terrible solution with multiple people but i am only currently trying to get the guns to function at all before I can improve upon their functionality.
Any help would be appreciated, Thanks!

Edit: I do not need to hold the gun, I want it to orbit around me. Meaning that the problem cannot be solved by simply using my lookVector instead.

0
You're trying to make the CenterBrick face a player object itself, that's your issue. Also you don't need to call tostring directly on roblox types; print does that for you and they have a __tostring metamethod that formats the properties. And don't call wait in the conditional part of a while loop. Instead, call it in the body of the loop and use true as condition instead for an infinite loop. User#24403 69 — 5y
0
Oops, I gave the wrong client script. xForVowels 6 — 5y
0
The script from before was for troubleshooting purposes, my bad. xForVowels 6 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

this how I make my gun face cursor, (yeah, I hate those gun shoot out 360 degrees too). you cannot just point your gun to the mouse, because you hand is welded to the weapon, if you turn the gun, either the motor6D will break, or the hand is just looking weird.

so what you need to do, is turning humanoidRootPart to the mouse.hit


local character = player.character if character then local direction = Vector3.new(mouse.Hit.p.X, character.HumanoidRootPart.Position.Y, mouse.Hit.p.Z) if character:FindFirstChild("HumanoidRootPart") then character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position, direction) else character.Torso.CFrame = CFrame.new(character.Torso.Position, direction) end end
0
The thing is, I'm not trying to hold the gun, I'm trying to get multiple of the same gun to orbit around you. I am currently trying to get the gun to face the direction of my mouse, not my lookVector and whatnot. Sorry that I didn't explicitly state this in my post! xForVowels 6 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I forgot to add player as the first argument, consider this question, closed.

Answer this question