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.
What is the issue? I don’t seem to find a way to achieve it.
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)
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.
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)