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

How would I get where the player is clicking?

I'm making a game where you click an area and a brick spawns there, I'm currently stuck with how to find out where the player is clicking.

5 comments

0

I made a laser that shoots where the user clicks, Would you want me to show you the code for that?

0

I'm trying to convert it to place a block

0

Could you also explain it please?

0

I dont just want the code, I want to walk away knowing how I could do more things like this in the future

0

If you have skype I can screen share and show you the code and give you a walk through. I just made it so that it places the block.

1 answer

✓ Accepted answer

Put this code in a local script inside a tool. This code will place a block with the center of the block where the mouse clicked. You can change the size of the block and other variables for it in the part() function. I don't know how much this helped, but if you have questions feel free to add me on skype and ask me there. mstrgmrs is my skype.

local tool = script.Parent;
local player = game.Players.LocalPlayer;
local mouse = game.Players.LocalPlayer:GetMouse();
 
function part(pos)
	local part = Instance.new("Part", workspace);
	part.FormFactor = Enum.FormFactor.Custom;
	part.Material = Enum.Material.Neon;
	part.Size = Vector3.new(2, 1, 2);
	part.CFrame = pos;
	part.Rotation = Vector3.new(0, 0, 0);
	part.Anchored = true;
	part.CanCollide = false;
	part.Transparency = 0;
	return part;
end;

script.Parent.Equipped:connect(function()
	script.Parent.Activated:connect(function()
		part(mouse.Hit);
	end);
end);

This code here will make the block placed go to the nearest whole stud

local tool = script.Parent;
local player = game.Players.LocalPlayer;
local mouse = game.Players.LocalPlayer:GetMouse();
 
function part(pos)
	local part = Instance.new("Part", workspace);
	part.FormFactor = Enum.FormFactor.Custom;
	part.Material = Enum.Material.Neon;
	part.Size = Vector3.new(2, 1, 2);
	part.CFrame = CFrame.new(math.floor(pos.x), math.floor(pos.y), math.floor(pos.z));
	part.Rotation = Vector3.new(0, 0, 0);
	part.Anchored = true;
	part.CanCollide = false;
	part.Transparency = 0;
	return part;
end;

script.Parent.Equipped:connect(function()
	script.Parent.Activated:connect(function()
		part(mouse.Hit);
	end);
end);

The only difference between the two is the math.floor() for the position instead of the exact position.

6 comments

0

Explanation plz!

0

dont have skype btw

0

Discord?

0

What kind of an explanation do you need?

0

nvm i got it

0

That's good. I'm glad I could help.

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