Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I use Target Filter?

So, I'm trying to make a tycoon game where I can place down objects wherever I want. I don't want the mouse to target the preview model, and how would I go about doing that? This is what I have so far, and the Target Filter I'm trying to use is in there.

while wait() do
	mouse.TargetFilter = (prevmodel)
	local filter = mouse.TargetFilter(prevmodel)
	if mouse.Target ~= nil then
	if mouse.Target.Parent.Name == "Model" then
	else
		prevmodel:MoveTo(Vector3.new((math.floor(mouse.hit.p.X) +offset),(math.floor(mouse.hit.p.Y) +offset),(math.floor(mouse.hit.p.Z) +offset)))
	end
	end
	if script.TurnOff.Value == true then
		prevmodel:Remove()
		script.TurnOff.Value = false
		script.Disabled = true
	end
end

1 answer

when using the mouse.Target, it doesn't target models, so an easy fix is to set the TargetFilter to a part around the model. This part's name is hitbox and would inside the model, anchored,fully transparent, and CanCollide is false. Now with the hitbox position/size it so it's surrounding the model, then set TargetFilter to this part:

mouse.TargetFilter = prevmodel.hitbox

This discussion is preserved as it was. New answers, comments, and votes are closed.