Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I get where the player is clicking?

Asked by 7 years ago
Edited 7 years ago

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.

0
I made a laser that shoots where the user clicks, Would you want me to show you the code for that? MrLonely1221 701 — 7y
0
I'm trying to convert it to place a block MrLonely1221 701 — 7y
0
Could you also explain it please? connor12260311 383 — 7y
0
I dont just want the code, I want to walk away knowing how I could do more things like this in the future connor12260311 383 — 7y
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. MrLonely1221 701 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

0
Explanation plz! connor12260311 383 — 7y
0
dont have skype btw connor12260311 383 — 7y
0
Discord? MrLonely1221 701 — 7y
0
What kind of an explanation do you need? MrLonely1221 701 — 7y
View all comments (2 more)
0
nvm i got it connor12260311 383 — 7y
0
That's good. I'm glad I could help. MrLonely1221 701 — 7y
Ad

Answer this question