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.
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.