Tool to drag models only if their parent is a certain folder

  1. What do you want to achieve? I’m currently making a tool that allows the player to move a model when clicking in it and holding it. I don’t want every model in workspace, I want models that they’re in a certain folder.

  2. What is the issue? I don’t seem to find a way to achieve it.

  3. What solutions have you tried so far? I tried different posts that I find, but no one has what I need

This is my script

local Tool = script.Parent
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()

Tool.Equipped:Connect(function()
	local target = mouse.Target
	mouse.TargetFilter = workspace.Folder:GetDescendants()
	Tool.Activated:Connect(function()
		mouse.Move:Connect(function()
			if target ~= nil and target:FindFirstAncestorWhichIsA("Model") then
				target.Parent:MoveTo(mouse.Hit.Position)
			end
		end)
	end)
end)
4 Likes

Well making a system that uses mouse target might not be the best for this. Instead get all the items inside of that folder into an array so you can loop through those items and check if the mouse is hovering over them. This removes the factor of using target filter since you are literally checking if the mouse is hovering over the object, and allows you to select things through walls if you want.

2 Likes

Thank you very much for the reply! I will try what you said, in case it works I will mark your answer as a solution

1 Like

I don’t seem to find a way to do that. I was trying with the following script:

local Tool = script.Parent
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local target = mouse.Target

Tool.Equipped:Connect(function()
	Tool.Activated:Connect(function()
		local Folder = workspace.Folder:GetDescendants()
		mouse.Move:Connect(function()
			for _,descendant in pairs(Folder) do
				if target ~= nil and target.Parent == descendant then
					target.Position = mouse.Hit.Position
				end
			end
		end)
	end)
end)

Tool.Unequipped:Connect(function()
	local Folder = workspace.Folder:GetDescendants()
	mouse.Move:Connect(function()
		for _,descendant in pairs(Folder) do
			if target ~= nil and target.Parent == descendant then
				target = nil
				target.Position = nil
			end
		end
	end)
end)

But isn’t really working, what I could do?

1 Like

I still haven’t found a solution to my problem, what can I do?