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 something on the mouse's X and Y position?

So I'm trying to recreate a really old 2010 game. I'm having trouble with something, obv.

When you select a tooland you click, it spawns a NPC. I got that done. My problem is, I want it to spawn where ever the mouse clicked.

code:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Button1Down:connect(function()
	local noob = game.Lighting.Noob
	noob.Parent = workspace
	noob.Position = Mouse(x, y)
end)

Any help?

1 answer

✓ Accepted answer

Use Mouse.Hit

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Button1Down:connect(function()
    local noob = game.Lighting.Noob:Clone()
    noob.Parent = workspace
    noob:MoveTo(Mouse.Hit.p)
end)

Also please don't use Lighting - It's deprecated as a form of storage.

4 comments

0

Then what do I use?

1

^ Idk, ServerStorage maybe? The Storage for the Server?

1

ServerStorage if only the server is going to look, or ReplicatedStorage if you need the client to know about it (In LocalScripts)

0

Thanks guys, your the best

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