I was just wondering how you would use your mouse to place a block on the floor according to where your mouse is.
COMMUNITY QUESTION
How do you place a object using your mouse?
1 answer
You can only get the player's mouse from the client, or in a Local Script.
--// Local Script that Runs on the client
local player = game.Players.LocalPlayer
local mouse = plr:GetMouse()
There are tons of events for the mouse that you can read about on the wiki. One thing you'll probably want is the mouse target.
--// Local Script that Runs on the client
local player = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local target
mouse.Button1Down:Connect(function()
target = mouse.Target
print(target.Name)
end)
You can get the CFrame of where the mouse it pointing in workspace using mouse.Hit.
--// Local Script that Runs on the client
local player = game.Players.LocalPlayer
local mouse = plr:GetMouse()
--// Makes a part where the mouse it pointing, when it clicks.
mouse.Button1Down:Connect(function()
local part = Instance.new("Part")
part.Parent = workspace
part.CFrame = mouse.Hit
end)
That should be everything you need to attempt this problem yourself!
Come back if you have any questions!
This discussion is preserved as it was. New answers, comments, and votes are closed.
