Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I spawn a part in the mouse's location?

local contextActionService = game:GetService("ContextActionService")

Move = script.Parent
plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
StartTimerValue = 5
MouseLocation = (mouse.Hit.p)

function onKeyPressOne()
			print("2")
			MouseLocation.Instance.new("Part",workspace)
		end
game.ContextActionService:BindAction("onKeyPressOne", onKeyPressOne, false, Enum.KeyCode.One)

My above script doesn't work. How do I get instance.new to spawn a brick at the coordinates provided by the mouse?

I would be thankful for help.

1 answer

✓ Accepted answer

Assuming "2" is printed, the problem is the line MouseLocation.Instance.new.... This is a problem for a few reasons:

  • MouseLocation.Instance is trying to get the 'Instance' property of 'MouseLocation' (which is a Vector3), which doesn't exist. Vector3s have X, Y, Z, and a few methods.
  • MouseLocation will not have been updated since the script started

Instead, in your function, do:

local part = Instance.new("Part", workspace)
part.Position = mouse.Hit.p

This discussion is preserved as it was. New answers, comments, and votes are closed.