Part.Position = Mouse.Hit.P is going ANYWHERE but my mouse position. Help?

As my question states, whenever I’m trying to set the part to the position of the mouse, it doesn’t work. My code looks like such:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local MousePos = Mouse.Hit.p
local UserInputService = game:GetService("UserInputService")
local RightArm = script.Parent["Right Arm"]
local TweenService = game:GetService("TweenService")

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.E then
			local Target = Instance.new("Part", game.Workspace)
			Target.Position = Vector3.new(MousePos)
		end
	end
end)

Any help to fix my issue please?

Why are you putting mousePos inside of a Vector3? It’s already a Vector3

removed the vector3.new() and now its spawning in some random spot in the map

Hold on let me see if I can quickly write up something

fixed issue:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local UserInputService = game:GetService("UserInputService")
local RightArm = script.Parent["Right Arm"]
local TweenService = game:GetService("TweenService")

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.E then
			local Target = Instance.new("Part", game.Workspace)
			Target.Position = Mouse.Hit.p
		end
	end
end)

Oh you fixed it nice, also dont do this
image

Set the parent after you create it

Thanks for help though!

30 lettters

1 Like

why not??
it saves me more lines

Set other properties before Parent after Instance.new

2 Likes

Never knew about that, thank you!

1 Like