Use mouse.UnitRay and create a ray instead.
This is what i do in my script
02 | RunService.Heartbeat:Connect( function () |
03 | local mouseRay = Mouse.UnitRay |
04 | RayInfo.FilterDescendantsInstances = { Tycoon, Character } |
05 | RayInfo.FilterType = Enum.RaycastFilterType.Blacklist |
07 | local raycastResult = game.Workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000 ) |
10 | local hit = raycastResult.Instance |
11 | if hit and not string.find(hit.Parent.Name, "Tycoon" ) then |
12 | if hit:IsA( "Part" ) and hit.Name:lower() = = "baseplate" then |
14 | SetModelBrickColor(Tycoon, BrickColor.new( "Bright green" )) |
17 | SetModelBrickColor(Tycoon, BrickColor.new( "Really red" )) |
20 | local Pos = raycastResult.Position |
29 | local newCFrame = CFrame.new(X, Y + yBuildingOffset, Z) |
30 | Tycoon:SetPrimaryPartCFrame(newCFrame) |