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

How would I go about making a block placing system?

Asked by 5 years ago

I have tried everything. Rounding up the xyz coordinate of where the player is clicking, the mouse.up function which seems to be deprecated etc. Could anyone head me in the right direction of making one? thx I dont need script just right idea since I cant seem to find onez

1
for a player clicking a location, do (that player):GetMouse() DeceptiveCaster 3761 — 5y
0
raycasting greatneil80 2647 — 5y

1 answer

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

In a local-script, get the player's mouse using game.Players.LocalPlayer:GetMouse() like MCAndRobloxUnited said. Then use the Button1Down function to check if the player has clicked. Send over a remote-event to the server with the player's mouse hit position and create a part at the mouse's hit position on there.

For an example,

-- In a Local Script

mouse.Button1Down:connect(function()
local Mouse = game.Players.LocalPlayer:GetMouse()
local pos = mouse.Hit.P
event:FireServer(pos)
end

-- In a Server Script


Event.OnServerEvent:connect(function(plr, mousepos) -- The first argument will always be the player, the rest will be the arguments you sent over from your local script, for our example that is the position of the click. local PlacePart = Instance.new("Part", workspace) -- Or whatever you're trying to spawn. PlacePart.Position = mousepos.Position -- This will teleport the part created when you clicked/PlacePart to the position of the click.

As you can see it's pretty simple but it may not be the best way to do it in terms of placement. There's other, better ways to do it but those are typically complicated, and require some maths.

[P.S this script was NOT created by me, I only added the part placement bit and explained it.]

https://scriptinghelpers.org/questions/35839/fe-how-would-i-replicate-mousehitp-to-the-server

1
Thankyou kind sir birdeater11 14 — 5y
Ad

Answer this question