Hey everyone,
I've been trying to use a click to move object script from YouTube and I've wanted to do 2 things. Note that this is in First Person Camera:
Keeping objects a certain distance away from the player when holding the object
Only be able to move specific objects, excluding the rest in the game.
I'll put my code below located in StarterPlayer>StarterPlayerScripts. I'd appreciate it if someone could let me know what to modify, or, even better, rewrite it so it fits the criteria.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local mtarget
local down
function clickObj()
if mouse.Target ~= nil and mouse.Target.Name ~= game.Workspace.Baseplate then
mtarget = mouse.Target
print(mtarget)
mouse.TargetFilter = mtarget
print(mouse.TargetFilter)
down = true
end
end
mouse.Button1Down:connect(clickObj)
function moveMouse()
if down and mtarget then
local posX,posY,posZ = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z
mtarget.Position = Vector3.new(posX,posY,posZ)
end
end
mouse.Move:connect(moveMouse)
function mouseDown()
down = false
mouse.Target = nil
mouse.TargetFilter = nil
end
mouse.Button1Up:connect(mouseDown)

5 comments
use code block plssss
No worries, sorted.
There's a community tutorial on devforum. https://devforum.roblox.com/t/dragging-objects-with-the-mouse/403766
I'll take a look
use the targetfilter property of the mouse