mouse.TargetFilter not working as intended

Here I’m trying to move a model, it moves. The thing is it is moving in very inconsistent increments while I havent even set any increments in the positionModel() function. I believe it’s something to do with mouse.TargetFilter, but I’ve tried everything I could think of.

Heres my code:

--[[ 
	
	AUTHOR: @anthlons
	
	DATE CREATED: 2/26/20
	
	DATE LAST EDITED: 3/12/20
	
	TYPE: LocalScript
]]--

----------- [ VARIABLES ] ----------

local TS = game:GetService("TweenService")

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local plot = game.Workspace:WaitForChild("Plots"):WaitForChild("Plot_"..plr.Name)
local placeItems = game.ReplicatedStorage:WaitForChild("HouseItems")
local placementEvents = game.ReplicatedStorage:WaitForChild("PlacementEvents")

local placingModel

local placing = false
----------- [ FUNCTIONS ] ----------

script.Parent.FocusLost:Connect(function(enterPressed, input)
	if enterPressed == true  then
		print("ep")
		if placeItems:FindFirstChild(script.Parent.Text:lower()) then
			print("found")
			local newObj = placeItems:FindFirstChild(script.Parent.Text:lower()):Clone()
			newObj.Parent = workspace
			placingModel = newObj
			placing = true
			print(newObj.Name)
			print("done")
			placeModel()
			mouse.TargetFilter = placingModel
		end
	else
		print(input)
		return
	end
end)


local function serverPlace(name, pos, rot)
	placementEvents.PlaceEvent:FireServer(name, pos, rot) -- args later
end

local function rotateModel()
	local Part = placingModel.PrimaryPart
	placingModel:SetPrimaryPartCFrame(Part.CFrame * CFrame.Angles(0, math.rad(90), 0))
	
end

local function positionModel()
	placingModel:MoveTo(Vector3.new(mouse.Hit.X, plot.Position.Y, mouse.Hit.Z))
end

function placeModel()
	while placing == true do
		wait()
		if mouse.Target then
			if mouse.Target == plot and mouse.TargetSurface == Enum.NormalId.Top then
				wait()
				positionModel()			
			end
		end
	end
end


local function completePlacement()
	local name = placingModel.Name
	placing = false
	serverPlace(name, placingModel.Hitbox.Position, placingModel.PrimaryPart.CFrame)
	print("pn"..name)
	placingModel:Destroy()
end
----------- [ EVENTS ] -------------

UIS.InputBegan:Connect(function(input, gp)
	if input.KeyCode == Enum.KeyCode.R and not gp then
		rotateModel()
	end
end)

mouse.Button1Down:Connect(function()
	if placing == true then
		completePlacement()
	end
end)

It’s probbly because you are using MoveTo, I don’t recommend using it as I had same problems. I can’t really give any other Solution right now though.

1 Like

Have you found a solution at all, I’m trying to get something done but I cant w/o the solution…

Try placing the targetFilter command in the place model function

1 Like