I was wondering what would be the best way to create a tool that creates a small part on a map when you click on it (precisely where you click). I was thinking raycasting would be the best, but im not sure, please let me know what you think!
Its a map comprised of small parts to resemble the real world map (but 2d of course)
The parts are meant to be server sided, just so you know im not looking for you to write code for me or anything i just want to know your opinion about what i should use to make this tool.
Why not make a local script, and have a separate server script?
Have the local script detect when you click the mouse, and fire an event with the mouse’s position to the server.
This is actually very easy to make, but it is important that you add some sort of cooldown or part limit to prevent abuse. Remember that these parts are visible to all players! Also, be sure to make a RemoteEvent called MakePart and place it in ReplicatedStorage.
Local Script (place inside the tool)
local mouse = game.Players.LocalPlayer:GetMouse()
script.Parent.Activated:Connect(function() -- Be sure this is parented to the tool!
game.ReplicatedStorage.MakePart:FireServer(mouse.Hit.Position)
end)
Server Script (doesn’t matter where it is, but I would recommend ServerScriptService)
game.ReplicatedStorage.MakePart.OnServerEvent:Connect(function(plr, hit)
-- TO PREVENT ABUSE, BE SURE TO ADD CHECKS (maybe a part limit?) HERE BEFORE CREATING THE PART!
local part = Instance.new("Part", game.Workspace) -- Create the part and parent it
part.Position = hit -- Change the position
-- You can add more code to customize the part.
end)
obviously the script in the tool will be a local script that fires a remote event, but like i said if i just use mouse.Hit.Position it will just get the position of the part it hits, and won’t be precise
like i said in the post i want the tool to be precise and mouse.Hit.Position would just give me the position of the part it hits rather than where the mouse actually hits, also i dont want you to write code for me i just wanted to know what i should use to make it work
That’s exactly what mouse.Hit.Position does. It seems to work well for me, and it places the parts exactly where I click. If you wanted to get the position of the part you click on, you would use mouse.Target.Position instead. In the two GIFs below, the position where the part will spawn is marked with a green ball.