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

How can i define where a player clicks?

Im doing a place tool which places blocks, but i can't define where somebody clicked, so i dont know where can i place the block. Here is the script.

	local Tool = script.Parent
 
Tool.Equipped:connect(function(Mouse)
	Mouse.Button1Down:connect(function(location)
			local part = Instance.new('Part')
	part.Parent = workspace
	part.Anchored = true
	part.CFrame = location
	local sbox = Instance.new("SelectionBox")
	sbox.Name = "sbox"
	sbox.Adornee = part
	sbox.Parent = part
	end)
		Mouse.Button1Up:connect(function()
		game.Workspace.Part.sbox:remove()
		wait(30)
		game.Workspace.Part:remove()
	end)
end)
	

1 answer

✓ Accepted answer

First get the players mouse with player:GetMouse() (assuming player is defined)

local mouse = player:GetMouse()

Then just get the mouse's click spot with mouse.Hit

local position = mouse.Hit

3 comments

0

I should point out that Hit is a variable, not a function, and so the parentheses are not necessary. Hit is also a CFrame, so keep that in mind. Finally, the mouse passed to the event will work just fine.

0

Oops, just noticed that I added parentheses on accident. Thanks for cathcing it

0

i changed the script into local and changed player into game.Players.LocalPlayer and did some things but then now it dosent give any error.

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